<template>
	<view class="doctor_visit">
		<view v-if="active === 1">
			<view class="input_box">
				<uni-forms ref="patientFormRef" err-show-type="toast" :modelValue="patient" :rules="patientRules">
					<uni-forms-item label="患者姓名" label-width="100px" required name="name" :error-message="false">
						<uni-easyinput v-model="patient.name" placeholder="请输入患者姓名" @input="nameChange" />
					</uni-forms-item>
					<uni-forms-item label="联系方式" label-width="100px" required name="tel" :error-message="false">
						<view class="mobileInput">
							<uni-easyinput class="" v-model="patient.tel" placeholder="请输入联系方式" :disabled="disabled" />
						</view>
					</uni-forms-item>
					<uni-forms-item label="性别" label-width="100px" required name="sex" :error-message="false">
						<uni-data-checkbox class="sexInput" v-model="patient.sex" :localdata="sexs"
							:disabled="disabled" />
					</uni-forms-item>
					<uni-forms-item label="出生日期" label-width="100px" required name="birthday" :error-message="false">
						<picker v-if="disabled == false" mode="date" fields="day" :value="patient.birthday"
							:end="birthdayEnd" @change="bindDateChange">
							<input v-model="patient.birthday" disabled placeholder="请选择出生日期" class="inputs" />
						</picker>
						<uni-easyinput v-if="disabled" v-model="patient.birthday" :disabled="disabled" />
					</uni-forms-item>
					<uni-forms-item label="身份证号" label-width="100px">
						<uni-easyinput v-model="patient.certno" placeholder="请输入身份证号" />
					</uni-forms-item>
					<uni-forms-item label="挂号费" label-width="100px">
						<uni-easyinput disabled value="10元" />
					</uni-forms-item>
				</uni-forms>
			</view>
			<view class="case_box">
				<view class="case_header">
					<view>门诊病历</view>
					<view class="case_right">
						<button class="button" plain type="primary" size="mini" @click="showConfig">配置</button>
						<button class="button" v-if="patient.id" plain type="primary" size="mini"
							@click="getHcList">历史病历</button>
						<button class="button" plain type="primary" size="mini" @click="addTemplateFun">存模板</button>
						<button class="button" plain type="primary" size="mini" @click="getTemplate(7)">模板</button>
					</view>
				</view>
				<uni-forms ref="caseHistoryFormRef" :modelValue="caseHistory" :rules="caseHistoryRules">
					<uni-forms-item :label="item.label" err-show-type="toast" :required="item.required"
						:name="item.formProp" :error-message="false" label-width="100px" v-for="item in showConfigList"
						:key="item.prop">
						<view v-if="item.type === 'dispose'">
							<view class="dispose_content">
								<view class="left_top">
									<uni-easyinput :inputBorder="false" v-model="caseHistory.upperLeft"
										placeholder="左上" />
								</view>
								<view class="right_top">
									<uni-easyinput :inputBorder="false" v-model="caseHistory.upperRight"
										placeholder="右上" />
								</view>
								<view class="left_bottom">
									<uni-easyinput :inputBorder="false" v-model="caseHistory.lowerLeft"
										placeholder="左下" />
								</view>
								<view style="width:50%">
									<uni-easyinput :inputBorder="false" v-model="caseHistory.lowerRight"
										placeholder="右下" />
								</view>
							</view>
							<uni-easyinput type="textarea" autoHeight style="width:50%"
								v-model="caseHistory.disposalContent" placeholder="请输入" />
						</view>
						<view v-else-if="item.formProp === 'medType'">
							<picker mode="selector" @change="medTypeChange" :value="caseHistory.medTypeName"
								range-key="key" :range="medTypeArray">
								<uni-easyinput v-model="caseHistory.medTypeName" placeholder="请输入医疗类型" />
							</picker>
						</view>
						<view v-else-if="item.formProp === 'algsHis'">
							<uni-easyinput @focus="handlerAlg" v-model="caseHistory[item.formProp]" placeholder="请选择" />
							<!-- <qianziyuSelect popupTitle="" @search="searchAlgSelect" @submit="algSubmit" @cancel="algCancel"
								:show="showAlgsHisSelect" type="checkbox" :dataLists="algDataLists"
								placeholder="输入工站名称搜索"></qianziyuSelect> -->
						</view>
						<view v-else-if="item.formProp === 'chfcomp'">
							<uni-easyinput @focus="handlerChchfcomp" v-model="caseHistory[item.formProp]"
								placeholder="请选择" />
							<!-- <qianziyuSelect popupTitle="" @search="searChchfcompSelect" @submit="chfcompSubmit" @cancel="chfcompCancel"
								:show="showChfcompSelect" type="checkbox" :dataLists="chfcompDataLists"
								placeholder="输入工站名称搜索"></qianziyuSelect> -->
						</view>
						<view v-else-if="item.formProp === 'tagIds'">
							<uni-easyinput @focus="handlerTag" v-model="caseHistory[item.formProp]" placeholder="请选择" />
							<!-- <qianziyuSelect popupTitle="" @search="searchTagSelect" @submit="tagSubmit" @cancel="tagCancel"
								:show="showTagSelect" type="checkbox" :dataLists="tagDataLists" placeholder="输入工站名称搜索">
							</qianziyuSelect> -->
						</view>
						<view v-else-if="item.formProp === 'diagnosis'">
							<!-- <text v-for="item in caseHistory.diagnosis" :key="item">{{item}}</text> -->
							<uni-easyinput @focus="handlerShowDiagnosis" v-model="caseHistory[item.formProp]"
								placeholder="请选择" />
						</view>
						<view v-else class="mobileInput">
							<uni-easyinput class="" v-model="caseHistory[item.formProp]" placeholder="请输入" />
						</view>
					</uni-forms-item>
				</uni-forms>
				<view class="physexm_toggle" @click="physexmToggle">{{showPhysexm?'隐藏':'编辑'}}体征检查
					<icon type="plus" size="26" />
				</view>
				<uni-forms ref="baseForm" :modelValue="caseHistory" label-position="top" v-if="showPhysexm">
					<uni-forms-item class="physexm_item" :label="item.label" label-width="70px"
						v-for="item in showPhysexmConfig" :key="item.prop">
						<view v-if="item.formType === 'BloodPressure'" class="BloodPressure">
							<uni-easyinput class="" v-model="caseHistory.physexmSystolicPre" placeholder="请输入" />
							<uni-easyinput class="" v-model="caseHistory.physexmDstlPre" placeholder="请输入" />
						</view>
						<view v-else-if="item.type === 'UDVA'" class="UDVA">
							<label>{{item.children[0].label}}</label>
							<uni-easyinput :inputBorder="false" class="" v-model="caseHistory[item.children[0].prop]"
								placeholder="请输入" />
							<label>{{item.children[1].label}}</label>
							<uni-easyinput :inputBorder="false" class="" v-model="caseHistory[item.children[1].prop]"
								placeholder="请输入" />
						</view>
						<view v-else class="mobileInput">
							<uni-easyinput class="" v-model="caseHistory[item.formProp]" placeholder="请输入" />
						</view>
					</uni-forms-item>
				</uni-forms>
			</view>
		</view>
		<view v-if="active === 2" style="padding-bottom: 50px;">
			<uni-grid :column="6" :highlight="true" :showBorder="false" @change="changeGrid">
				<uni-grid-item v-for="item in headerArr" :index="item.value" :key="item.value">
					<view class="grid-item-box" style="background-color: #fff; padding-top: 16rpx; ">
						<image :src="item.icon" mode="" style="width: 65rpx; height: 65rpx;"></image>

						<view class="text">{{item.label}}</view>
					</view>
				</uni-grid-item>
			</uni-grid>
			<view style="text-align: right; margin-top:20rpx;">
				<button class="button" plain type="primary" size="mini" @click="getHcList">历史病历</button>
				<button class="button" plain type="primary" size="mini" @click="addTemplateFun">存模板</button>
				<button class="button" plain type="primary" size="mini" @click="getTemplate(templateType)">模板</button>
			</view>
			<view v-for="(drugItem,index) in prescriptions" :key="index">
				<view v-if="drugItem.rxType === 1 && drugItem.rxType === activeHeader"
					style="padding: 14rpx; background: #fff;">
					<uni-row class="demo-uni-row">
						<uni-col :span="21">
							<view style="margin-left: 8rpx;">
								<uni-combox :candidates="drugList" @change="changeDrug($event,drugItem.details)"
									:clear="clearDrug" @focus="inputDrug" :drug="true" @input="inputDrug" placeholder="请输入内容">
									<!-- <template #option="scope">
										<view>
											<view class="w-100">
												<text class="name mr-10">{{scope.row.name}}</text>
												<text>单价：{{scope.row.retailPrice}} 元</text>
											</view>
											<view class="flex w-100">
												<text class="mr-10">{{scope.row.specification}}</text>
												<text class="mr-10"> {{scope.row.manufacturer}}</text>
												<text class="mr-10">库存: {{scope.row.stockQtyDescribe}}</text>
											</view>
										</view>
									</template> -->
								</uni-combox>
								<!-- drugSelectore -->
							</view>
						</uni-col>
						<uni-col :span="3">
							<view class="scanIcon" @click="onClickScan">
								<image src="../../../static/saoma.png" mode=""></image>
							</view>
						</uni-col>
					</uni-row>
				</view>
				<view v-if="drugItem.rxType === 1&& drugItem.rxType === activeHeader" class="drugContent"
					:class="drugItem.details.length ===0?'mh-300':''">
					<view style="border-bottom:1px solid #e3e3e3" v-for="(item,index) in drugItem.details" :key="index">
						<view class="forms_rows">
							<view class="flex space-between">
								<text class="name">{{item.name}}</text>
								<view class="flex">
									<text>单价</text>
									<view style="width:70px;" class="flex mr-10">
										<uni-easyinput :clearable="false" :inputBorder="false" trim="all"
											v-model="item.retailPrice" placeholder="请输入">
										</uni-easyinput>
										<!-- retailPrice   pric -->
										<text class="color:red">元</text>
									</view>
									<uni-number-box class="mr-10" v-model="item.cnt" />
									<!-- cnt -->
									<text>{{item.unit}}</text>
								</view>
								<uni-icons type="trash-filled"
								v-if="drugItem.details.length > 0"
									@click="deleteDrugDetails(drugItem.details,index,item.name)" color="#F56C6C"
									size="20"></uni-icons>
							</view>
							<view>{{item.specification}} {{item.manufacturer}}</view>
							<view class="flex">
								<view class="flex">
									<text class="white-nowrap">剂型</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'dosform',dosformList)"
										:value="item.dosform" :range="dosformList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.dosform" placeholder="选择剂型" />
										<!-- dosform -->
									</picker>
								</view>
								<view class="flex">
									<text class="white-nowrap">单次剂量</text>
									<view style="width:70px">
										<uni-easyinput :clearable="false" :inputBorder="false" trim="all"
											v-model="item.dosDscr" placeholder="请输入">
										</uni-easyinput>
										<!-- rxDoscnt -->
									</view>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'dosDscrUnit',unitFrquList)"
										:value="item.dosDscrUnit" :range="unitFrquList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.dosDscrUnit"
											placeholder="选择单位" />
										<!-- sinDosunt -->

									</picker>
									<label class="white-nowrap">
										<radio :value="true" style="transform:scale(0.7)" :checked="item.enableSplit" />
										拆零
										<!-- 	 -->
									</label>
								</view>
							</view>
							<view class="flex">
								<view class="flex">
									<text class="white-nowrap">频率</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'rxFrquName',usedFrquList)"
										:value="item.rxFrquName" :range="usedFrquList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.rxFrquName"
											placeholder="选择频率" />
									</picker>
								</view>
								<view class="flex mr-10">
									<text class="white-nowrap">天数</text>
									<uni-easyinput :clearable="false" :inputBorder="false" trim="all"
										v-model="item.days" placeholder="请输入内容"></uni-easyinput>
									<text class="white-nowrap">天</text>
								</view>
								<view class="flex">
									<text class="white-nowrap">用法</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'rxUsedWayName',usageList)"
										:value="item.rxUsedWayName" :range="usageList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.rxUsedWayName"
											placeholder="请选择" />
									</picker>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view v-if="drugItem.rxType === 1&& drugItem.rxType === activeHeader" class="flex drugFoot">
					<text>医嘱</text>
					<uni-easyinput :clearable="false" :inputBorder="false" trim="all" v-model="drugItem.doctorAdvice"
						placeholder="请输入内容"></uni-easyinput>
					<!-- doctorAdvice -->
				</view>
				<view v-if="drugItem.rxType === 1&& drugItem.rxType === activeHeader" class="drugFoot flex surcharges">
					<button @click="addSurcharges(drugItem.details_Fujiafei)" type="primary" size="mini">附加费用</button>
					<view>
						共计：<text class="red">{{drugItem.details.length}}</text>件
						小计：<text class="red">{{drugItem.subtotal}}</text>元
					</view>
				</view>
				<view v-if="drugItem.rxType === 1&& drugItem.rxType === activeHeader" class="surchargesContent">
					<view class="flex surchargesItem space-between" v-for="(item,index) in drugItem.details_Fujiafei"
						:key="index">
						<uni-combox style="width:150px" :disabled="item.check" @input="querySurchargesSelector"
							@change="changSurcharges($event,drugItem.details_Fujiafei,index)" labelKey="name"
							:candidates="surcharges" placeholder="请选择" v-model="item.surchargeName"></uni-combox>
						<view style="width:150px" class="flex">
							<uni-easyinput :clearable="false" trim="all" v-model="item.amt" placeholder="请输入内容">
							</uni-easyinput>
							<text class="white-nowrap">元</text>
							<text class="white-nowrap">/次</text>
						</view>
						<uni-icons type="trash-filled" @click="deleteSurcharges(drugItem.details_Fujiafei,index)"
							size="20"></uni-icons>
					</view>
				</view>
				<view v-if="drugItem.rxType === 2&& drugItem.rxType === activeHeader"
					style="padding: 14rpx; background: #fff;">
					<uni-row class="demo-uni-row">
						<uni-col :span="injectingDrugIndex>1?16:21">
							<view class="flex" style="margin-left: 8rpx;">
								<text class="white-nowrap">注射组
									<text class="red">{{drugItem.index}}</text></text>
								<uni-combox class="w-100" :candidates="drugList"
									@change="changeDrug($event,drugItem.details)" :drug="true" :clear="clearDrug" @focus="inputDrug"
									@input="inputDrug" placeholder="请输入内容">
									<!-- <template #option="scope">
										<view>
											<view class="w-100">
												<text class="name mr-10">{{scope.row.name}}</text>
												<text>单价：{{scope.row.retailPrice}} 元</text>
											</view>
											<view class="flex w-100">
												<text class="mr-10">{{scope.row.specification}}</text>
												<text class="mr-10"> {{scope.row.manufacturer}}</text>
												<text class="mr-10">库存: {{scope.row.stockQtyDescribe}}</text>
											</view>
										</view>
									</template> -->
								</uni-combox>
							</view>
						</uni-col>
						<uni-col :span="3">
							<view class="scanIcon" @click="onClickScan">
								<image src="../../../static/saoma.png" mode=""></image>
							</view>
						</uni-col>
						<uni-col :span="5" v-if="injectingDrugIndex> 1">
							<button @click="deleteDrug(2,drugItem.index)" type="error" size="mini">删组</button>
						</uni-col>
					</uni-row>
				</view>
				<view v-if="drugItem.rxType === 2&& drugItem.rxType === activeHeader" class="drugContent"
					:class="drugItem.details.length ===0?'mh-300':''">
					<view style="border-bottom:1px solid #e3e3e3" v-for="(item,index) in drugItem.details" :key="index">
						<view class="forms_rows">
							<view class="flex space-between">
								<text class="name">{{item.name}}</text>
								<view class="flex">
									<text>单价</text>
									<uni-easyinput :clearable="false" :inputBorder="false" trim="all"
										v-model="item.retailPrice" placeholder="请输入内容"></uni-easyinput>
									<uni-number-box class="mr-10" v-model="item.cnt" />
									<text>{{item.unit}}</text>
								</view>
								<uni-icons type="trash-filled"
								v-if="drugItem.details.length > 0"
									@click="deleteDrugDetails(drugItem.details,index,item.name)" color="#F56C6C"
									size="20"></uni-icons>
							</view>
							<view>{{item.specification}} {{item.manufacturer}}</view>
							<view class="flex">
								<view class="flex">
									<text class="white-nowrap">默认剂量</text>
									<text style="width:30px">{{item.rxDoscnt}}</text>
									<text style="width:30px">{{item.dosDscrUnit}}</text>
								</view>
								<view class="flex">
									<text class="white-nowrap">单次剂量</text>
									<uni-easyinput :clearable="false" :inputBorder="false" trim="all"
										v-model="item.rxDoscnt" placeholder="请输入"></uni-easyinput>
									<text style="width:30px">{{item.dosDscrUnit}}</text>
									<!-- <picker mode="selector" @change="administrativeChange"
										:value="patient.administrative" :range="administrativeArray">
										<uni-easyinput :inputBorder="false" v-model="patient.sinDosunt" placeholder="选择单位" />
									</picker> -->
									<label class="white-nowrap">
										<radio :value="true" style="transform:scale(0.7)" :checked="item.enableSplit" />
										皮试
									</label>
								</view>
							</view>
							<view class="flex">
								<view class="flex">
									<text class="white-nowrap">剂型</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'dosform',dosformList)"
										:value="item.dosform" :range="dosformList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.dosform" placeholder="选择剂型" />
										<!-- dosform -->
									</picker>
								</view>
								<view class="flex">
									<text class="white-nowrap">单次数量</text>
									<uni-easyinput :inputBorder="false" trim="all" v-model="item.rxDoscnt"
										placeholder="请输入">
									</uni-easyinput>
									<text style="width:30px">{{item.dosDscrUnit}}</text>
								</view>
								<label class="white-nowrap">
									<radio :value="true" style="transform:scale(0.7)" :checked="item.enableSplit" />拆零
								</label>
							</view>
							<view class="flex">
								<view class="w-30 flex">
									<text class="white-nowrap">用法</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'rxUsedWayName',usageList)"
										:value="item.rxUsedWayName" :range="usageList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.rxUsedWayName"
											placeholder="请选择" />
									</picker>
								</view>
								<view class="w-30 flex">
									<text class="white-nowrap">频率</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'rxFrquName',usedFrquList)"
										:value="item.rxFrquName" :range="usedFrquList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.rxFrquName"
											placeholder="选择频率" />
									</picker>
								</view>
								<view class="w-30 flex">
									<text class="white-nowrap">天数</text>
									<uni-easyinput :inputBorder="false" trim="all" v-model="item.days"
										placeholder="请输入"></uni-easyinput>
									天
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="flex addDrug"
					v-if="drugItem.rxType === 2&& drugItem.rxType === activeHeader && drugItem.index ===injectingDrugIndex">
					<button @click="addDrug(2)" type="primary" size="mini">加组</button>
				</view>
				<view
					v-if="drugItem.rxType === 2&& drugItem.rxType === activeHeader && drugItem.index ===injectingDrugIndex"
					class="flex drugFoot">
					<text>医嘱</text>
					<uni-easyinput :inputBorder="false" trim="all" v-model="drugItem.doctorAdvice" placeholder="请输入内容">
					</uni-easyinput>
				</view>
				<view
					v-if="drugItem.rxType === 2&& drugItem.rxType === activeHeader && drugItem.index ===injectingDrugIndex"
					class="drugFoot flex surcharges">
					<button @click="addSurcharges(drugItem.details_Fujiafei)" type="primary" size="mini">附加费用</button>
					<view>
						共计：<text class="red">{{drugItem.details.length}}</text>件
						小计：<text class="red">{{drugItem.subtotal}}</text>元
					</view>
				</view>
				<view
					v-if="drugItem.rxType === 2&& drugItem.rxType === activeHeader && drugItem.index ===injectingDrugIndex"
					class="surchargesContent">
					<view class="flex surchargesItem space-between" v-for="(item,index) in drugItem.details_Fujiafei"
						:key="index">
						<uni-combox style="width:150px" :disabled="item.check" @input="querySurchargesSelector"
							@change="changSurcharges($event,drugItem.details_Fujiafei,index)" labelKey="name"
							:candidates="surcharges" placeholder="请选择" v-model="item.surchargeName"></uni-combox>
						<view style="width:150px" class="flex">
							<uni-easyinput :clearable="false" trim="all" v-model="item.amt" placeholder="请输入内容">
							</uni-easyinput>
							<text class="white-nowrap">元</text>
							<text class="white-nowrap">/次</text>
						</view>
						<uni-icons type="trash-filled" @click="deleteSurcharges(drugItem.details_Fujiafei,index)"
							size="20"></uni-icons>
					</view>
				</view>
				<view v-if="drugItem.rxType === 4&& drugItem.rxType === activeHeader"
					style="padding: 14rpx; background: #fff;">
					<uni-row class="demo-uni-row">
						<uni-col :span="herbalDrugIndex>1?16:21">
							<view style="margin-left: 8rpx;">
								<uni-combox :candidates="drugList" @change="changeDrug($event,drugItem.details)"
									:clear="clearDrug" @focus="inputDrug" @input="inputDrug" placeholder="请输入内容">
									<template #option="scope">
										<view>
											<view class="w-100">
												<text class="name mr-10">{{scope.row.name}}</text>
												<text>单价：{{scope.row.retailPrice}} 元</text>
											</view>
											<view class="flex w-100">
												<text class="mr-10">{{scope.row.specification}}</text>
												<text class="mr-10"> {{scope.row.manufacturer}}</text>
												<text class="mr-10">库存: {{scope.row.stockQtyDescribe}}</text>
											</view>
										</view>
									</template>
								</uni-combox>
								<!-- drugSelectore -->
							</view>
						</uni-col>
						<uni-col :span="3">
							<view class="scanIcon" @click="onClickScan">
								<image src="../../../static/saoma.png" mode=""></image>
							</view>
						</uni-col>
						<uni-col :span="5" v-if="herbalDrugIndex> 1">
							<button @click="deleteDrug(4,drugItem.index)" type="error" size="mini">删除</button>
						</uni-col>

					</uni-row>
				</view>
				<view v-if="drugItem.rxType === 4&& drugItem.rxType === activeHeader" class="drugContent"
					:class="drugItem.details.length ===0?'mh-300':''">
					<view style="border-bottom:1px solid #e3e3e3" v-for="(item,index) in drugItem.details" :key="index">
						<view class="forms_rows" style="border-bottom:1px solid #e3e3e3">
							<view class="flex space-between">
								<text class="name">{{item.name}}</text>
								<view class="flex">
									<text>单价</text>
									<uni-easyinput :clearable="false" :inputBorder="false" trim="all"
										v-model="item.retailPrice" placeholder="请输入内容"></uni-easyinput>
									<uni-number-box class="mr-10" v-model="item.cnt" />
									<text>{{item.unit}}</text>
								</view>
								<uni-icons type="trash-filled" v-if="drugItem.details.length > 0" @click="deleteDrugDetails(drugItem.details,index,item.name)" color="#F56C6C" size="20"></uni-icons>
							</view>
							<view class="flex">
								<view class="flex">
									<text class="white-nowrap">剂型</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'dosform',dosformList)"
										:value="item.dosform" :range="dosformList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.dosform" placeholder="选择剂型" />
										<!-- dosform -->
									</picker>
								</view>
								<view class="flex">
									<text class="white-nowrap">特殊处理</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'specialTreatment',specialtreatmentList)"
										:value="item.specialTreatment" :range="specialtreatmentList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.specialTreatment"
											placeholder="选择特殊处理" />
									</picker>

								</view>
							</view>
						</view>
						<view class="forms_rows">
							<view class="flex">
								<view class="flex drugItem w-30 mr-10">
									<text class="white-nowrap">总副数</text>
									<uni-easyinput :inputBorder="false" trim="all" v-model="item.dosage"
										placeholder="请输入内容">
									</uni-easyinput>
								</view>
								<view class="flex drugItem w-30 mr-10">
									<text class="white-nowrap">频率</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'rxFrquName',usedFrquList)"
										:value="item.rxFrquName" :range="usedFrquList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.rxFrquName"
											placeholder="选择频率" />
									</picker>
								</view>
								<view class="flex drugItem w-30">
									<text class="white-nowrap">天数</text>
									<uni-easyinput :inputBorder="false" trim="all" v-model="item.days"
										placeholder="请输入内容">
									</uni-easyinput>
								</view>
							</view>
							<view class="flex">
								<view class="flex drugItem  w-30 mr-10">
									<text class="white-nowrap">用量</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'dosage',usedFrquList)"
										:value="item.dosage" :range="usedFrquList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.dosage" placeholder="选择单位" />
									</picker>
								</view>
								<view class="flex drugItem w-30 mr-10">
									<text class="white-nowrap">用法</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'rxUsedWayName',zyusageaskList)"
										:value="item.rxUsedWayName" :range="zyusageaskList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.rxUsedWayName"
											placeholder="选择单位" />
									</picker>
								</view>
								<view class="flex drugItem w-30">
									<text class="white-nowrap">煎药方式</text>
									<uni-easyinput :inputBorder="false" trim="all" v-model="item.decoctingMethod"
										placeholder="请输入内容">
									</uni-easyinput>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view v-if="drugItem.rxType === 4&& drugItem.rxType === activeHeader && drugItem.details.length> 0"
					class="flex drugFoot">
					<text>医嘱</text>
					<uni-easyinput :inputBorder="false" trim="all" v-model="drugItem.doctorAdvice" placeholder="请输入内容">
					</uni-easyinput>
				</view>
				<view v-if="drugItem.rxType === 4&& drugItem.rxType === activeHeader && drugItem.details.length> 0"
					class="drugFoot flex surcharges">
					<button @click="addSurcharges(drugItem.details_Fujiafei)" type="primary" size="mini">附加费用</button>
					<view>
						共计：<text class="red">{{drugItem.details.length}}</text>件
						小计：<text class="red">{{drugItem.subtotal}}</text>元
					</view>
				</view>
				<view v-if="drugItem.rxType === 4&& drugItem.rxType === activeHeader && drugItem.details.length> 0"
					class="surchargesContent">
					<view class="flex surchargesItem space-between" v-for="(item,index) in drugItem.details_Fujiafei"
						:key="index">
						<uni-combox style="width:150px" :disabled="item.check" @input="querySurchargesSelector"
							@change="changSurcharges($event,drugItem.details_Fujiafei,index)" labelKey="name"
							:candidates="surcharges" placeholder="请选择" v-model="item.surchargeName"></uni-combox>
						<view style="width:150px" class="flex">
							<uni-easyinput :clearable="false" trim="all" v-model="item.amt" placeholder="请输入内容">
							</uni-easyinput>
							<text class="white-nowrap">元</text>
							<text class="white-nowrap">/次</text>
						</view>
						<uni-icons type="trash-filled" @click="deleteSurcharges(drugItem.details_Fujiafei,index)"
							size="20"></uni-icons>
					</view>
				</view>
				<view class="flex addDrug"
					v-if="drugItem.rxType === 4&& drugItem.rxType === activeHeader && drugItem.index ===herbalDrugIndex">
					<button @click="addDrug(4)" type="primary" size="mini">加处方</button>
				</view>
				<view v-if="drugItem.rxType === 7&& drugItem.rxType === activeHeader"
					style="padding: 14rpx; background: #fff;">
					<uni-row class="demo-uni-row">
						<uni-col :span="smearDrugIndex>1?16:21">
							<view style="margin-left: 8rpx;">
								<uni-combox :candidates="drugList" @change="changeDrug($event,drugItem.details)"
									:clear="clearDrug" @focus="inputDrug" @input="inputDrug" placeholder="请输入内容">
									<template #option="scope">
										<view style="">
											<view class="w-100">
												<text class="name mr-10">{{scope.row.name}}</text>
												<text>单价：{{scope.row.retailPrice}} 元</text>
											</view>
											<view class="flex w-100">
												<text class="mr-10">{{scope.row.specification}}</text>
												<text class="mr-10"> {{scope.row.manufacturer}}</text>
												<text class="mr-10">库存: {{scope.row.stockQtyDescribe}}</text>
											</view>
										</view>
									</template>
								</uni-combox>
								<!-- drugSelectore -->
							</view>
						</uni-col>
						<uni-col :span="3">
							<view class="scanIcon" @click="onClickScan">
								<image src="../../../static/saoma.png" mode=""></image>
							</view>
						</uni-col>
						<uni-col :span="5" v-if="smearDrugIndex >1">
							<button @click="deleteDrug(7,drugItem.index)" type="error" size="mini">删除</button>
						</uni-col>
					</uni-row>
				</view>
				<view v-if="drugItem.rxType === 7&& drugItem.rxType === activeHeader" class="drugContent"
					:class="drugItem.details.length ===0?'mh-300':''">
					<view style="border-bottom:1px solid #e3e3e3" v-for="(item,index) in drugItem.details" :key="index">
						<view class="forms_rows" style="border-bottom:1px solid #e3e3e3">
							<view class="flex space-between">
								<text class="name">{{item.name}}</text>
								<view class="flex">
									<text>剂量</text>
									<uni-number-box class="mr-10" v-model="item.cnt" />
									<!-- cnt -->
									<text>{{item.unit}}</text>
								</view>
								<uni-icons type="trash-filled" v-if="drugItem.details.length > 0" @click="deleteDrugDetails(drugItem.details,index,item.name)" color="#F56C6C" size="20"></uni-icons>
							</view>
						</view>
						<view class="forms_rows">
							<view class="flex flex-wrap space-between">
								<view class="flex w-30 drugItem mr-10">
									<text class="white-nowrap">名称</text>
									<uni-easyinput :inputBorder="false" trim="all" v-model="item.name"
										placeholder="请输入内容">
									</uni-easyinput>
								</view>
								<view class="flex w-30 drugItem mr-10">
									<text class="white-nowrap">价格</text>
									<uni-easyinput :inputBorder="false" trim="all" v-model="item.pricePerSticker"
										placeholder="请输入">
									</uni-easyinput>
									<text>元</text>
								</view>
								<view class="flex w-30 drugItem">
									<text class="white-nowrap">总贴数</text>
									<uni-easyinput :inputBorder="false" trim="all" v-model="item.quantity"
										placeholder="请输入">
									</uni-easyinput>
								</view>
							</view>
							<view class="flex flex-wrap space-between">
								<view class="flex w-30  drugItem mr-10">
									<text class="white-nowrap">调法</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'modulationMethod',modulationmethodList)"
										:value="item.modulationMethod" :range="modulationmethodList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.modulationMethod"
											placeholder="选择调法" />
									</picker>
								</view>
								<view class="flex w-30 drugItem mr-10">
									<text class="white-nowrap">用法</text>
									<picker mode="selector"
										@change="changePicker($event,drugItem.details,index,'rxUsedWayName',ftusageaskList)"
										:value="item.rxUsedWayName" :range="ftusageaskList" range-key="key">
										<uni-easyinput :inputBorder="false" :disabled="false" v-model="item.rxUsedWayName"
											placeholder="选择用法" />
									</picker>

								</view>
								<view class="flex w-30 drugItem">
									<text class="white-nowrap">执行天数</text>
									<uni-easyinput :inputBorder="false" trim="all" v-model="item.days"
										placeholder="请输入内容">
									</uni-easyinput>
									天
								</view>
							</view>
							<view class="flex drugItem">
								<text class="white-nowrap">部位</text>
								<uni-easyinput :inputBorder="false" trim="all" v-model="item.applicationSite"
									placeholder="请选择">
								</uni-easyinput>
							</view>
						</view>
					</view>
				</view>
				<view v-if="drugItem.rxType === 7&& drugItem.rxType === activeHeader && drugItem.details.length> 0"
					class="flex drugFoot">
					<text>医嘱</text>
					<uni-easyinput :inputBorder="false" trim="all" v-model="drugItem.doctorAdvice" placeholder="请输入内容">
					</uni-easyinput>
				</view>
				<view v-if="drugItem.rxType === 7&& drugItem.rxType === activeHeader && drugItem.details.length> 0"
					class="drugFoot flex surcharges">
					<button @click="addSurcharges(drugItem.details_Fujiafei)" type="primary" size="mini">附加费用</button>
					<view>
						共计：<text class="red">{{drugItem.details.length}}</text>件
						小计：<text class="red">{{drugItem.subtotal}}</text>元
					</view>
				</view>
				<view v-if="drugItem.rxType === 7&& drugItem.rxType === activeHeader && drugItem.details.length> 0"
					class="surchargesContent">
					<view class="flex surchargesItem space-between" v-for="(item,index) in drugItem.details_Fujiafei"
						:key="index">
						<uni-combox style="width:150px" :disabled="item.check" @input="querySurchargesSelector"
							@change="changSurcharges($event,drugItem.details_Fujiafei,index)" labelKey="name"
							:candidates="surcharges" placeholder="请选择" v-model="item.surchargeName"></uni-combox>
						<view style="width:150px" class="flex">
							<uni-easyinput :clearable="false" trim="all" v-model="item.amt" placeholder="请输入内容">
							</uni-easyinput>
							<text class="white-nowrap">元</text>
							<text class="white-nowrap">/次</text>
						</view>
						<uni-icons type="trash-filled" @click="deleteSurcharges(drugItem.details_Fujiafei,index)"
							size="20"></uni-icons>
					</view>
				</view>
				<view class="flex addDrug"
					v-if="drugItem.rxType === 7&& drugItem.rxType === activeHeader && drugItem.index ===smearDrugIndex">
					<button @click="addDrug(7)" type="primary" size="mini">加组</button>
				</view>
				<view v-if="drugItem.rxType === 8&& drugItem.rxType === activeHeader"
					style="padding: 14rpx; background: #fff;">
					<uni-row class="demo-uni-row">
						<uni-col :span="21">
							<view style="margin-left: 8rpx;">
								<uni-combox :candidates="drugList" @change="changeDrug($event,drugItem.details)"
									:clear="clearDrug" @focus="inputDrug" @input="inputDrug" placeholder="请输入内容">
									<template #option="scope">
										<view>
											<view class="w-100">
												<text class="name mr-10">{{scope.row.name}}</text>
												<text>单价：{{scope.row.retailPrice}} 元</text>
											</view>
											<view class="flex w-100">
												<text class="mr-10">{{scope.row.specification}}</text>
												<text class="mr-10"> {{scope.row.manufacturer}}</text>
												<text class="mr-10">库存: {{scope.row.stockQtyDescribe}}</text>
											</view>
										</view>
									</template>
								</uni-combox>
								<!-- drugSelectore -->
							</view>
						</uni-col>
						<uni-col :span="3">
							<view class="scanIcon" @click="onClickScan">
								<image src="../../../static/saoma.png" mode=""></image>
							</view>
						</uni-col>
					</uni-row>
				</view>
				<view v-if="drugItem.rxType === 8&& drugItem.rxType === activeHeader" class="drugContent"
					:class="drug.length ===0?'mh-300':''">
					<view style="border-bottom:1px solid #e3e3e3" v-for="(item,index) in drugItem.details" :key="index">
						<view class="forms_rows">
							<view class="flex space-between">
								<text class="name">{{item.name}}</text>
								<view class="flex">
									<text class="white-nowrap">单价</text>
									<uni-easyinput :inputBorder="false" trim="all" v-model="item.cnt" placeholder="请输入">
									</uni-easyinput>
									<text class="mr-10">元</text>
									<uni-number-box class="mr-10" />
									<text>{{item.unit}}</text>
								</view>
								<uni-icons type="trash-filled" v-if="drugItem.details.length > 0" @click="deleteDrugDetails(drugItem.details,index,item.name)" color="#F56C6C" size="20"></uni-icons>
							</view>
						</view>
						<view class="flex drugFoot">
							<text>医嘱</text>
							<uni-easyinput :inputBorder="false" trim="all" v-model="drugItem.doctorAdvice"
								placeholder="请输入内容">
							</uni-easyinput>
						</view>
					</view>
				</view>

				<view v-if="drugItem.rxType === 8&& drugItem.rxType === activeHeader" class="drugFoot flex surcharges">
					<button @click="addSurcharges(drugItem.details_Fujiafei)" type="primary" size="mini">附加费用</button>
					<view>
						共计：<text class="red">{{drugItem.details.length}}</text>件
						小计：<text class="red">{{drugItem.subtotal}}</text>元
					</view>
				</view>
				<view v-if="drugItem.rxType === 8&& drugItem.rxType === activeHeader" class="surchargesContent">
					<view class="flex surchargesItem space-between" v-for="(item,index) in drugItem.details_Fujiafei"
						:key="index">
						<uni-combox style="width:150px" :disabled="item.check" @input="querySurchargesSelector"
							@change="changSurcharges($event,drugItem.details_Fujiafei,index)" labelKey="name"
							:candidates="surcharges" placeholder="请选择" v-model="item.surchargeName"></uni-combox>
						<view style="width:150px" class="flex">
							<uni-easyinput :clearable="false" trim="all" v-model="item.amt" placeholder="请输入内容">
							</uni-easyinput>
							<text class="white-nowrap">元</text>
							<text class="white-nowrap">/次</text>
						</view>
						<uni-icons type="trash-filled" @click="deleteSurcharges(drugItem.details_Fujiafei,index)"
							size="20"></uni-icons>
					</view>
				</view>
				<view v-if="drugItem.rxType === 3&& drugItem.rxType === activeHeader"
					style="padding: 14rpx; background: #fff;">
					<uni-row class="demo-uni-row">
						<uni-col :span="21">
							<view style="margin-left: 8rpx;">
								<uni-combox :candidates="drugList" @change="changeDrug($event,drugItem.details)"
									:clear="clearDrug" @focus="inputDrug" @input="inputDrug" placeholder="请输入内容">
									<template #option="scope">
										<view>
											<view class="w-100">
												<text class="name mr-10">{{scope.row.name}}</text>
												<text>单价：{{scope.row.retailPrice}} 元</text>
											</view>
											<view class="flex w-100">
												<text class="mr-10">{{scope.row.specification}}</text>
												<text class="mr-10"> {{scope.row.manufacturer}}</text>
												<text class="mr-10">库存: {{scope.row.stockQtyDescribe}}</text>
											</view>
										</view>
									</template>
								</uni-combox>
								<!-- drugSelectore -->
							</view>
						</uni-col>
						<uni-col :span="3">
							<view class="scanIcon" @click="onClickScan">
								<image src="../../../static/saoma.png" mode=""></image>
							</view>
						</uni-col>
					</uni-row>
				</view>
				<view v-if="drugItem.rxType === 3&& drugItem.rxType === activeHeader" class="drugContent"
					:class="drug.length ===0?'mh-300':''">
					<view style="border-bottom:1px solid #e3e3e3" v-for="(item,index) in drugItem.details" :key="index">
						<view class="forms_rows">
							<view class="name">
								<text>{{item.name}}</text>
							</view>
							<view class="flex space-between">
								<text class="white-nowrap">单价</text>
								<uni-easyinput :inputBorder="false" trim="all" v-model="item.inputVal"
									placeholder="请输入">
								</uni-easyinput>
								<text class="mr-10">元</text>
								<uni-number-box class="mr-10" v-model="item.cnt" />
								<text>{{item.unit}}</text>
							</view>
							<uni-icons type="trash-filled" v-if="drugItem.details.length > 0" @click="deleteDrugDetails(drugItem.details,index,item.name)" color="#F56C6C" size="20"></uni-icons>
						</view>
					</view>
				</view>
				<view v-if="drugItem.rxType === 3&& drugItem.rxType === activeHeader" class="flex drugFoot">
					<text>医嘱</text>
					<uni-easyinput :inputBorder="false" trim="all" v-model="drugItem.doctorAdvice" placeholder="请输入内容">
					</uni-easyinput>
				</view>
				<view v-if="drugItem.rxType === 3&& drugItem.rxType === activeHeader" class="drugFoot flex surcharges">
					<button @click="addSurcharges(drugItem.details_Fujiafei)" type="primary" size="mini">附加费用</button>
					<view>
						共计：<text class="red">{{drugItem.details.length}}</text>件
						小计：<text class="red">{{drugItem.subtotal}}</text>元
					</view>
				</view>
				<view v-if="drugItem.rxType === 3&& drugItem.rxType === activeHeader" class="surchargesContent">
					<view class="flex surchargesItem space-between" v-for="(item,index) in drugItem.details_Fujiafei"
						:key="index">
						<uni-combox style="width:150px" :disabled="item.check" @input="querySurchargesSelector"
							@change="changSurcharges($event,drugItem.details_Fujiafei,index)" labelKey="name"
							:candidates="surcharges" placeholder="请选择" v-model="item.surchargeName"></uni-combox>
						<view style="width:150px" class="flex">
							<uni-easyinput :clearable="false" trim="all" v-model="item.amt" placeholder="请输入内容">
							</uni-easyinput>
							<text class="white-nowrap">元</text>
							<text class="white-nowrap">/次</text>
						</view>
						<uni-icons type="trash-filled" @click="deleteSurcharges(drugItem.details_Fujiafei,index)"
							size="20"></uni-icons>
					</view>
				</view>
			</view>
			<!-- 	<view v-for="(drugItem,index) in prescriptions" :key="index">
				
			</view>
			<view v-for="(drugItem,index) in prescriptions" :key="index">
				
			</view>
			<view v-for="(drugItem,index) in prescriptions" :key="index">
				
			</view>
			<view v-for="(drugItem,index) in prescriptions" :key="index">
				
			</view>
			<view v-for="(drugItem,index) in prescriptions" :key="index">
				
			</view> -->
		</view>
		<view class="btn" v-if="active === 1">
			<button class="button" type="primary" size="default" @click="next">下一步</button>
		</view>
		<view class="footBtn" v-if="active === 2">
			<span @click="back">返回病历</span>
			<view class="flex">
				<view style="color:red" class="mr-10">
					<view class="red">￥ {{totalAmount}}</view>
					<!-- <view>挂号费：￥</view> -->
				</view>
				<button class="button" style="backgroundColor:#E6A23C;width:90px;border-radius: 0;" type="primary"
					size="default" @click="onPricing">划价</button>
				<button class="button" style="backgroundColor:#409EFF;width:90px;border-radius: 0;" type="primary"
					size="default" @click="onSettle">收费</button>
			</view>
		</view>
		<inputMask @closeMask="closeMask" topVal="46" :topShow="topShowFlag">
			<view class="li" v-for="(item,index) in peopleData" :key="index" @click="peopleClick(item)">
				<image class="sexFlag" :src="index%2==0?sexFlagImage[0]:sexFlagImage[1]" mode=""></image>
				<text class="name">{{item.name}}</text>
				<text class="age">{{item.age}}岁</text>
				<text class="mobile">{{item.tel}}</text>
			</view>
		</inputMask>
		<uni-popup ref="configPopupRef" background-color="#fff">
			<!-- <view class="popup_header">
				<span>病历配置</span>
			</view> -->
			<checkbox-group @change="changeConfig">
				<view class="config_content" v-for="(item,index) in configArr" :key="index">
					<h2 class="config_title">{{item.title}}</h2>
					<view class="config_check">
						<label class="config_item" v-for=" children in item.children" :key="children.prop">
							<checkbox :disabled="children.disabled" style="transform:scale(0.7)"
								:checked="configData[children.prop]" :value="children.prop" />{{children.label}}
						</label>
					</view>
				</view>
			</checkbox-group>
			<view class="config_foot">
				<button class="button" type="primary" size="default" @click="onDefault">恢复默认</button>
				<button class="button" type="primary" size="default" @click="onSaveConfig">确定</button>
			</view>
		</uni-popup>
		<uni-popup ref="templateRef" background-color="#fff">
			<!-- <view class="popup_header">
				<span>模板列表</span>
			</view> -->
			<view class="template_content">
				<uni-collapse accordion>
					<uni-collapse-item :show-arrow="false" v-for="(item,index) in templateList" :key="index">
						<template v-slot:title>
							<view class="flex templateItem">
								<text>{{item.name}}</text>
								<view class="flex ">
									<button class="mr-10" type="primary"
										style="color:#409EFF;backgroundColor:#fff;borderColor:#409EFF" plain="true"
										size="mini" @click="getDetailsTemplate(item)">查看</button>
									<button class="" type="primary"
										style="color:#ffffff;backgroundColor:#409EFF;borderColor:#409EFF" size="mini"
										@click.stop="setDetailsTemplate(item)">使用</button>
								</view>
							</view>
						</template>
						<view>
							<view class="flex templateItem" style="justify-content: left;" v-for="item in templateArr"
								:key="item.prop">
								<text>{{item.label}}</text>
								<text>{{templateDetails[item.prop]}}</text>
							</view>
						</view>
					</uni-collapse-item>
				</uni-collapse>
			</view>
		</uni-popup>
		<uni-popup ref="hcRef" background-color="#fff">
			<!-- <view class="popup_header">
				<span>历史病历</span>
			</view> -->
			<view class="template_content">
				<uni-collapse accordion>
					<uni-collapse-item :show-arrow="false" @change="getDetailsHc" v-for="(item,index) in hcList"
						:key="index">
						<template v-slot:title>
							<view class="flex templateItem hcItem">
								<view>
									<view>医生：{{item.doctor}}</view>
									<view>时间：{{item.visitTime}}</view>
									<view>诊断{{item.dises}}</view>
								</view>
								<view class="flex flex-wrap">
									<button class="mr-10 flex-wrap" type="primary"
										style="color:#409EFF;backgroundColor:#fff;borderColor:#409EFF" plain="true"
										size="mini" @click="getDetailsHc(item)">查看病历</button>
									<button class="flex-wrap" type="primary"
										style="color:#ffffff;backgroundColor:#409EFF;borderColor:#409EFF" size="mini"
										@click.stop="setDetailsHc(item)">复用病历</button>
								</view>
							</view>
						</template>
						<view>
							<!-- <view class="flex templateItem" style="justify-content: left;" v-for="item in templateArr" :key="item.prop">
								<text>{{item.label}}</text>
								<text>{{templateDetails[item.prop]}}</text>
							</view> -->
							<uni-forms :modelValue="hcDetailsVal" style="padding: 0 15rpx;">
								<uni-forms-item :label="item.label" :name="item.formProp" :error-message="false"
									label-width="100px" v-for="item in showConfigList" :key="item.prop">
									<view v-if="item.type === 'dispose'">
										<view class="dispose_content">
											<view style="width:50%">
												<!-- <uni-easyinput :inputBorder="false" v-model="caseHistory.lowerRight"
										placeholder="右下" /> -->
												<view class="left_top">{{hcDetailsVal.caseHistory.upperLeft}}</view>
												<view class="right_top">{{hcDetailsVal.caseHistory.upperRight}}</view>
												<view class="left_bottom">{{hcDetailsVal.caseHistory.lowerLeft}}</view>
												<view style="width:50%">{{hcDetailsVal.caseHistory.lowerRight}}</view>
											</view>
										</view>
										<uni-easyinput type="textarea" autoHeight disabled style="width:50%"
											v-model="hcDetailsVal.caseHistory.disposalContent" placeholder="请输入" />
									</view>
									<view v-else-if="item.formProp === 'medType'">
										<view>{{hcDetailsVal.caseHistory.medTypeName}}</view>
									</view>
									<view v-else class="mobileInput">
										<view>{{hcDetailsVal.caseHistory[item.formProp]}}</view>
									</view>
								</uni-forms-item>
							</uni-forms>
							<uni-grid-item v-for="item in hcHeaderArr" :key="item.value">
								<text class="text">{{item.label}}</text>
							</uni-grid-item>
							<view v-for="(drugItem,index) in prescriptions" :key="index">
								<view v-if="drugItem.rxType === 1&& drugItem.rxType === activeHeader"
									class="drugContent" :class="drugItem.details.length ===0?'mh-300':''">
									<view style="border-bottom:1px solid #e3e3e3"
										v-for="(item,index) in drugItem.details" :key="index">
										<view class="forms_rows">
											<view class="flex space-between">
												<text class="name">{{item.name}}</text>
												<view class="flex">
													<text>单价</text>
													<view style="width:70px;" class="flex mr-10">
														<text>{{item.retailPrice}}</text>
														<!-- retailPrice   pric -->
														<text class="color:red">元</text>
													</view>
													<text>总量</text>
													{{item.cnt}}
													<!-- cnt -->
													<text>{{item.unit}}</text>
												</view>
												<uni-icons type="trash-filled"
													@click="deleteDrugDetails(drugItem.details,index,item.name)"
													color="#F56C6C" size="20"></uni-icons>
											</view>
											<view class="flex">
												<view class="flex">
													<text class="white-nowrap">剂型</text>
													<text>{{item.dosform}}</text>
												</view>
												<view class="flex">
													<text class="white-nowrap">单次剂量</text>
													<view style="width:70px">
														<text>{{item.dosDscr}}</text>
														<!-- rxDoscnt -->
													</view>
													<text class="white-nowrap">单位</text>
													<text>{{item.dosDscrUnit}}</text>
													<text class="white-nowrap">是否拆零</text>
													<text>{{item.enableSplit?'是':'否'}}</text>
												</view>
											</view>
										</view>
									</view>
								</view>
								<view v-if="drugItem.rxType === 2&& drugItem.rxType === activeHeader"
									class="drugContent" :class="drugItem.details.length ===0?'mh-300':''">
									<view style="border-bottom:1px solid #e3e3e3"
										v-for="(item,index) in drugItem.details" :key="index">
										<view class="forms_rows">
											<view class="flex space-between">
												<text class="name">{{item.name}}</text>
												<view class="flex">
													<text>单价</text>
													<text>{{item.cnt}}</text>
													<text>总量: {{item.unit}}</text>
												</view>
											</view>
											<view class="flex">
												<view class="flex">
													<text class="white-nowrap">默认剂量</text>
													<text style="width:30px">{{item.rxDoscnt}}</text>
													<text style="width:30px">{{item.dosDscrUnit}}</text>
												</view>
												<view class="flex">
													<text class="white-nowrap">单次剂量</text>
													<text>{{item.dosDscrUnit}}</text>
													<text class="white-nowrap">是否皮试</text>
													<text>{{item.enableSplit?'是':'否'}}</text>
												</view>
											</view>
											<view class="flex">
												<view class="flex">
													<text class="white-nowrap">剂型</text>
													<text>{{item.dosform}}</text>
												</view>
												<view class="flex">
													<text class="white-nowrap">单次数量</text>
													<text>{{item.rxDoscnt}}</text>
													<text style="width:30px">{{item.dosDscrUnit}}</text>
												</view>
												<label class="white-nowrap">
													<text class="white-nowrap">是否拆零</text>
													<text>{{item.enableSplit?'是':'否'}}</text>
												</label>
											</view>
											<view class="flex">
												<view class="w-30 flex">
													<text class="white-nowrap">用法</text>
													<text>{{item.rxUsedWayName}}</text>
												</view>
												<view class="w-30 flex">
													<text class="white-nowrap">频率</text>
													<text>{{item.rxFrquName}}</text>
												</view>
												<view class="w-30 flex">
													<text class="white-nowrap">天数</text>
													<text>{{item.days}}</text>
													天
												</view>
											</view>
										</view>
									</view>
								</view>
								<view v-if="drugItem.rxType === 4&& drugItem.rxType === activeHeader"
									class="drugContent" :class="drugItem.details.length ===0?'mh-300':''">
									<view style="border-bottom:1px solid #e3e3e3"
										v-for="(item,index) in drugItem.details" :key="index">
										<view class="forms_rows" style="border-bottom:1px solid #e3e3e3">
											<view class="flex space-between">
												<text class="name">{{item.name}}</text>
												<view class="flex">
													<text>单价</text>
													<text>{{item.cnt}}</text>
													<text>{{item.unit}}</text>
												</view>
												<uni-icons type="trash-filled" color="#F56C6C" size="20"></uni-icons>
											</view>
											<view class="flex">
												<view class="flex">
													<text class="white-nowrap">剂型</text>
													<text>{{item.dosform}}</text>
												</view>
												<view class="flex">
													<text class="white-nowrap">特殊处理</text>
													<text>{{item.specialTreatment}}</text>
												</view>
											</view>
										</view>
										<view class="forms_rows">
											<view class="flex">
												<view class="flex drugItem w-30 mr-10">
													<text class="white-nowrap">总副数</text>
													<text>{{item.dosage}}</text>
												</view>
												<view class="flex drugItem w-30 mr-10">
													<text class="white-nowrap">频率</text>
													<text>{{item.rxFrquName}}</text>
												</view>
												<view class="flex drugItem w-30">
													<text class="white-nowrap">天数</text>
													<text>{{item.days}}</text>
												</view>
											</view>
											<view class="flex">
												<view class="flex drugItem  w-30 mr-10">
													<text class="white-nowrap">用量</text>
													<text>{{item.dosage}}</text>
												</view>
												<view class="flex drugItem w-30 mr-10">
													<text class="white-nowrap">用法</text>
													<text>{{item.rxUsedWayName}}</text>
												</view>
												<view class="flex drugItem w-30">
													<text class="white-nowrap">煎药方式</text>
													<text>{{item.decoctingMethod}}</text>
												</view>
											</view>
										</view>
									</view>
								</view>
								<view v-if="drugItem.rxType === 7&& drugItem.rxType === activeHeader"
									class="drugContent" :class="drugItem.details.length ===0?'mh-300':''">
									<view style="border-bottom:1px solid #e3e3e3"
										v-for="(item,index) in drugItem.details" :key="index">
										<view class="forms_rows" style="border-bottom:1px solid #e3e3e3">
											<view class="flex space-between">
												<text class="name">{{item.name}}</text>
												<view class="flex">
													<text>剂量</text>
													<text>{{item.cnt}}</text>
													<!-- cnt -->
													<text>{{item.unit}}</text>
												</view>
											</view>
										</view>
										<view class="forms_rows">
											<view class="flex flex-wrap space-between">
												<view class="flex w-30 drugItem mr-10">
													<text class="white-nowrap">名称</text>
													<text>{{item.name}}</text>
												</view>
												<view class="flex w-30 drugItem mr-10">
													<text class="white-nowrap">价格</text>
													<text>{{item.pricePerSticker}}</text>
													<text>元</text>
												</view>
												<view class="flex w-30 drugItem">
													<text class="white-nowrap">总贴数</text>
													<text>{{item.quantity}}</text>
												</view>
											</view>
											<view class="flex flex-wrap space-between">
												<view class="flex w-30  drugItem mr-10">
													<text class="white-nowrap">调法</text>
													<text>{{item.modulationMethod}}</text>
												</view>
												<view class="flex w-30 drugItem mr-10">
													<text class="white-nowrap">用法</text>
													<text>{{item.rxUsedWayName}}</text>

												</view>
												<view class="flex w-30 drugItem">
													<text class="white-nowrap">执行天数</text>
													<text>{{item.days}}</text>
													天
												</view>
											</view>
											<view class="flex drugItem">
												<text class="white-nowrap">部位</text>
												<text>{{item.applicationSite}}</text>
											</view>
										</view>
									</view>
								</view>
								<view v-if="drugItem.rxType === 8&& drugItem.rxType === activeHeader"
									class="drugContent" :class="drug.length ===0?'mh-300':''">
									<view style="border-bottom:1px solid #e3e3e3"
										v-for="(item,index) in drugItem.details" :key="index">
										<view class="forms_rows">
											<view class="flex space-between">
												<text class="name">{{item.name}}</text>
												<view class="flex">
													<text class="white-nowrap">单价</text>
													<text>{{item.cnt}}</text>
													<text class="mr-10">元</text>
													<text>{{item.unit}}</text>
												</view>
											</view>
										</view>
									</view>
								</view>
							</view>

						</view>
					</uni-collapse-item>

				</uni-collapse>
			</view>
		</uni-popup>
		<uni-popup ref="addTemplateRef" background-color="#fff">
			<!-- <view class="popup_header">
				<span>添加模板</span>
			</view> -->
			<view style="min-height:400px;padding:30px 8px 0 8px;">
				<uni-forms ref="baseForm" :modelValue="templateData">
					<uni-forms-item label="模板名称" label-width="100px" required>
						<uni-easyinput v-model="templateData.name" placeholder="请输入模板名称" />
					</uni-forms-item>
					<uni-forms-item label="模板类别" label-width="100px" required>
						<uni-easyinput v-model="templateData.pattern" placeholder="请输入模板类别" />
					</uni-forms-item>
					<uni-forms-item label="模板说明" label-width="100px" required>
						<uni-easyinput v-model="templateData.details" placeholder="请输入模板说明" />
					</uni-forms-item>
					<view class="flex" style="justify-content: center;margin-top: 15px;">
						<radio-group @change="radioChange">
							<label class="radio">
								<radio :value="true" :checked="templateData.isPersonalTemplate === true" />个人专用
							</label>
							<label class="radio">
								<radio :value="false" :checked="templateData.isPersonalTemplate === false" />诊所共享
							</label>
						</radio-group>
					</view>
					<view class="template_foot">
						<button class="button" type="primary" size="mini" @click="onClose">取消</button>
						<button class="button" type="primary" size="mini" @click="onSaveTemplate">确定</button>
					</view>
				</uni-forms>
			</view>
		</uni-popup>
		<uni-popup ref="alertDialogRef" type="dialog">
			<uni-popup-dialog type="info" cancelText="取消" confirmText="确定" :title="alertTitle" :content="alertContent"
				@confirm="dialogConfirm"></uni-popup-dialog>
		</uni-popup>
		<!-- <uni-popup ref="surchargesSelectorRef" background-color="#fff" @change="changeSurcharges">
			<uni-table ref="table" class="aaaa" :loading="loading" border stripe type="selection"
				@selection-change="selectionChange">
				<uni-tr>
					<uni-th align="center">名称</uni-th>
					<uni-th width="80" align="center">金额(元)</uni-th>
					<uni-th width="80" align="center">单位</uni-th>

				</uni-tr>
				<uni-tr v-for="(item, index) in surcharges" :key="index">
					<uni-td>{{ item.date }}</uni-td>
					<uni-td>
						<view class="name">{{ item.name }}</view>
					</uni-td>
					<uni-td align="center">{{ item.address }}</uni-td>
				</uni-tr>
			</uni-table>
			<view class="flex">
				<button class="button" style="margin:0" type="primary" size="default" @click="onDefault">取消</button>
				<button class="button" style="margin:0" type="primary" size="default" @click="onSave">确定</button>
			</view>
		</uni-popup> -->
		<uni-popup ref="diagnosisRef" background-color="#fff">
			<!-- <view class="popup_header">
				<span>诊断</span>
			</view> -->
			<view class="h-500">
				<view class="diagnosisInput">
					<uni-easyinput :inputBorder="false" trim="all" placeholder="请输入关键字搜索"
						@input="inputDiagnosis($event)"></uni-easyinput>
				</view>
				<view class="diagnosisContent flex">
					<view class="activeDiagnosisItem flex" v-for="item in caseHistory.diagnosis" :key="item.id">{{item}}
						<uni-icons @click="deleteDiagnosis(item)" color="#606266" style="margin-left: 10rpx;"
							type="clear" size="20"></uni-icons>
					</view>
				</view>
				<view class="flex diagnosisSelect">
					<view class="w-100" v-if="diseaseNameList.length > 0">请选择诊断</view>
					<view @click="handlerDiagnosis(item)" class="diagnosisItem" v-for="item in diseaseNameList"
						:key="item.id">{{item.name}}</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="algRef" background-color="#fff">
			<!-- <view class="popup_header">
				<span>诊断</span>
			</view> -->
			<view class="h-500">
				<!-- <view class="diagnosisInput">
					<uni-easyinput :inputBorder="false" trim="all" placeholder="请输入关键字搜索"
						@input="inputTypeList($event,4)"></uni-easyinput>
				</view> -->
				<view class="diagnosisContent flex">
					<view class="activeDiagnosisItem flex" v-for="item in caseHistory.algsHis" :key="item.id">{{item}}
						<uni-icons @click="deleteAlg(item)" color="#606266" style="margin-left: 10rpx;" type="clear"
							size="20"></uni-icons>
					</view>
				</view>
				<view class="flex diagnosisSelect">
					<!-- <view class="w-100" v-if="diseaseNameList.length > 0">请选择诊断</view> -->
					<view @click="handlerAlg(item)" class="diagnosisItem" v-for="item in algList" :key="item.id">
						{{item.name}}</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="hchfcompRef" background-color="#fff">
			<!-- <view class="popup_header">
				<span>诊断</span>
			</view> -->
			<view class="h-500">
				<!-- <view class="diagnosisInput">
					<uni-easyinput :inputBorder="false" trim="all" placeholder="请输入关键字搜索"
						@input="inputTypeList($event,1)"></uni-easyinput>
				</view> -->
				<view class="diagnosisContent flex">
					<view class="activeDiagnosisItem flex" v-for="item in caseHistory.chfcomp" :key="item.id">{{item}}
						<uni-icons @click="deleteChfcomp(item)" color="#606266" style="margin-left: 10rpx;" type="clear"
							size="20"></uni-icons>
					</view>
				</view>
				<view class="flex diagnosisSelect">
					<!-- <view class="w-100" v-if="diseaseNameList.length > 0">请选择诊断</view> -->
					<view @click="handlerDiagnosis(item)" class="diagnosisItem" v-for="item in chfcompList"
						:key="item.id">{{item.name}}</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="tagRef" background-color="#fff">
			<!-- <view class="popup_header">
				<span>诊断</span>
			</view> -->
			<view class="h-500">
				<!-- <view class="diagnosisInput">
					<uni-easyinput :inputBorder="false" trim="all" placeholder="请输入关键字搜索"
						@input="inputTypeList($event,5)"></uni-easyinput>
				</view> -->
				<view class="diagnosisContent flex">
					<view class="activeDiagnosisItem flex" v-for="item in caseHistory.tagIds" :key="item.id">{{item}}
						<uni-icons @click="deleteTag(item)" color="#606266" style="margin-left: 10rpx;" type="clear"
							size="20"></uni-icons>
					</view>
				</view>
				<view class="flex diagnosisSelect">
					<!-- <view class="w-100" v-if="diseaseNameList.length > 0">请选择诊断</view> -->
					<view @click="handlerDiagnosis(item)" class="diagnosisItem" v-for="item in tagList" :key="item.id">
						{{item.name}}</view>
				</view>
			</view>
		</uni-popup>
		<!-- <inputMask @closeMask="closeMask" topVal="160" :topShow="algsHisFlag">
			<view class="li" v-for="(item,index) in peopleData" :key="index" @click="peopleClick(item)">
				<image class="sexFlag" :src="index%2==0?sexFlagImage[0]:sexFlagImage[1]" mode=""></image>
				<text class="name">{{item.name}}</text>
				<text class="age">{{item.age}}岁</text>
				<text class="mobile">{{item.tel}}</text>
			</view>
		</inputMask>
		<inputMask @closeMask="closeMask" topVal="360" :topShow="tagFlag">
			<view class="li" v-for="(item,index) in peopleData" :key="index" @click="peopleClick(item)">
				<image class="sexFlag" :src="index%2==0?sexFlagImage[0]:sexFlagImage[1]" mode=""></image>
				<text class="name">{{item.name}}</text>
				<text class="age">{{item.age}}岁</text>
				<text class="mobile">{{item.tel}}</text>
			</view>
		</inputMask> -->
	</view>
</template>

<script setup>
	import {
		ref,
		watchEffect,
		nextTick,
		computed,
		watch
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import gridItem from '../../../uni_modules/uview-plus/libs/config/props/gridItem';
	import listVue from '../clinicalReception/list.vue';
	// import qianziyuSelect from '../../../components/qianziyu-select/qianziyu-select.vue'
	// import { patientSelector } from '../../../api/view/doctorVisit.js';
	import inputMask from "../subscribeRegistration/InputMask.vue";
	import {
		patientSelector,
		medTypeSelector,
		allergicTypeSelector,
		tagSelector,
		queryConfig,
		restoreDefault,
		queryTemplate,
		drugSelectore,
		addTemplate,
		dosformSelector,
		unitFrquSelector,
		usedFrquSelector,
		usageSelector,
		modulationmethodSelector,
		ftusageaskSelector,
		zyusageaskSelector,
		surchargesSelector,
		therapySelector,
		pricing,
		diseaseNameSelector,
		getListByType,
		specialtreatmentSelector,
		settlement,
		detailsTemplate,
		saveTreated,
		queryHCPage,
		hCDetails,
		placeAnOrder,
		initialization,
		reservationPage
	} from "/api/view/doctorVisit.js";
	// 患者逻辑
	const patientList = ref([]); // 患者列表
	const patient = ref({
		name: ""
	});
	const caseHistory = ref({})
	const active = ref(1)
	const disabled = ref(true);
	let patientObj = null;
	const templateType = ref(2)
	const peopleData = ref([])
	const medTypeArray = ref([])
	const allergicArray = ref([])
	const tagArray = ref([])
	const configList = ref([])
	const configPopupRef = ref(null)
	const surchargesSelectorRef = ref(null)
	const surcharges = ref([])
	const showPhysexm = ref(false)
	const templateList = ref([])
	const drugList = ref([])
	const therapyList = ref([])
	const diseaseNameList = ref([])
	const activeHeader = ref(1)
	const diagnosisRef = ref(null)
	const hcRef = ref(null)
	const hcList = ref([])
	const details_Fujiafei = ref([])
	const surchargesList = ref([])
	const templateRef = ref(null)
	const drug = ref([])
	const algRef = ref(true)
	const hchfcompRef = ref(null)
	const tagpRef = ref(true)
	const addTemplateRef = ref(null)
	const hcDetailsVal = ref({
		caseHistory: {}
	})
	const dises = ref([])
	const hcHeaderArr = ref([])
	const algList = ref([])
	const chfcompList = ref([])
	const tagList = ref([])
	// const drugItem.details = ref([])
	const clearDrug = ref(0)
	// const drugItem.details = ref([])
	const deleteList = ref([])
	const deleteIndex = ref(0)
	const configArr = ref([{
			title: '选择需要得病历字段',
			children: [{
					prop: 'isMedType',
					label: '医疗类别',
					disabled: true,
					required: true,
					formProp: 'medType'
				},
				{
					prop: 'isDiagnosis',
					label: '诊断',
					disabled: true,
					required: true,
					formProp: 'diagnosis'
				},
				{
					prop: 'isAlgsHis',
					label: '过敏史',
					formProp: 'algsHis'
				},
				{
					prop: 'isChfcomp',
					label: '患者主诉',
					formProp: 'chfcomp'
				},
				{
					prop: 'isTagIds',
					label: '标签',
					formProp: 'tagIds'
				},
				{
					prop: 'isDiseNow',
					label: '现病史',
					formProp: 'diseNow'
				},
				{
					prop: 'isPastHistory',
					label: '既往史',
					formProp: 'pastHistory'
				},
				{
					prop: 'isOtherCheck',
					label: '其他检查',
					formProp: 'otherCheck'
				},
				{
					prop: 'isLook',
					label: '望闻问切',
					formProp: 'look'
				},
				{
					prop: 'isDispose',
					label: '处置',
					type: 'dispose',
					formProp: 'disposalContent',
					labelPosition: 'top'
				},
				{
					prop: 'isPsnHis',
					label: '个人史',
					formProp: 'psnHis'
				},
				{
					prop: 'isEpidemicHistory',
					label: '流行病史',
					formProp: 'epidemicHistory'
				},
				{
					prop: 'isFmhis',
					label: '家族遗传史',
					formProp: 'fmhis'
				},
				{
					prop: 'isMenaHis',
					label: '月经婚育史（女性）',
					formProp: 'menaHis'
				},
				{
					prop: 'isDdvice',
					label: '医嘱',
					formProp: 'doctorAdvice'
				},
			]
		},
		{
			title: '选择需要得体征检查字段',
			children: [{
					prop: 'isPhysexmTprt',
					label: '体温',
					formProp: 'physexmTprt',
					type: 'physexm'
				},
				{
					prop: 'isHeartRate',
					label: '心率',
					formProp: 'heartRate',
					type: 'physexm'
				},
				{
					prop: 'isPhysexmVentFrqu',
					label: '呼吸',
					formProp: 'physexmVentFrqu',
					type: 'physexm'
				},
				{
					prop: 'isPhysexmWt',
					label: '体重',
					formProp: 'physexmWt',
					type: 'physexm'
				},
				{
					prop: 'isBloodPressure',
					label: '血压',
					type: 'physexm',
					formType: 'BloodPressure',
					children: [{
							formProp: 'physexmSystolicPre'
						},
						{
							formProp: 'physexmDstlPre'
						}
					]
				},
				{
					prop: 'isPhysicalExamination',
					label: '体格检查',
					formProp: 'physexmOrdnStas',
					type: 'physexm'
				},
				{
					prop: 'isUDVA',
					label: '裸眼远近视力',
					type: 'physexm',
					formType: 'UDVA',
				},
				{
					prop: 'isWGNV',
					label: '戴镜远近视力',
					type: 'physexm',
					formProp: 'UDVA'
				},
			]
		}
	])
	const templateDetails = ref({})
	const templateArr = [{
			label: '模板名称：',
			prop: 'name'
		},
		{
			label: '处方类别：',
			prop: 'rxType'
		},
		{
			label: '说明：',
			prop: ''
		},
		{
			label: '过敏史：',
			prop: 'algsHis'
		},
		{
			label: '患者主诉：',
			prop: 'chfcomp'
		},
		{
			label: '现病史：',
			prop: 'diseNow'
		},
		{
			label: '其他检查：',
			prop: 'otherCheck'
		},
		{
			label: '医疗类别：',
			prop: 'medType'
		},
		{
			label: '诊断：',
			prop: 'diagnosis'
		},
		{
			label: '标签：',
			prop: 'tagIds'
		},
		{
			label: '既往史：',
			prop: 'pastHistory'
		},
	]
	const sexFlagImage = ref(["../../../static/icon/男.png", "../../../static/icon/女.png"]);
	const showConfigList = ref([])
	const showPhysexmConfig = ref([])
	const templateData = ref({})
	const reservationId = ref(0)
	const settlementData = ref([])
	// 单选数据源
	const sexs = ref([{
		text: '男',
		value: '1'
	}, {
		text: '女',
		value: '2'
	}])
	// 出生日期
	const date = ref("2023-10-10")
	let nowDate = new Date();
	let nowYear = nowDate.getFullYear();
	let nowMonth = nowDate.getMonth() + 1;
	let nowDay = nowDate.getDate();
	const birthdayEnd = ref()
	patient.value.birthday = `${nowYear}-${nowMonth<10?'0'+nowMonth:nowMonth}-${nowDay<10?'0'+nowDay:nowDay}`
	birthdayEnd.value = `${nowYear}-${nowMonth<10?'0'+nowMonth:nowMonth}-${nowDay<10?'0'+nowDay:nowDay}`
	const searchPat = (val) => {
		patientSelector({
			SearchKey: val
		}).then((res) => {
			patientList.value = res.data;
		});
	}
	const topShowFlag = ref(false)
	const algsHisFlag = ref(false)
	const tagFlag = ref(false)
	const catyData = ref({})
	const caseHistoryRules = {
		medType: {
			rules: [{
				required: true,
				errorMessage: '请选择医疗类型',
			}]
		},
		diagnosis: {
			rules: [{
				required: true,
				errorMessage: '请填写诊断',
			}]
		}
	}
	const caseHistoryFormRef = ref(null)
	const patientRules = {
		name: {
			rules: [{
				required: true,
				errorMessage: '请填写姓名',
			}]
		},
		tel: {
			rules: [{
				required: true,
				errorMessage: '请填写电话',
			}]
		},
		sex: {
			rules: [{
				required: true,
				errorMessage: '请选择性别',
			}]
		},
		birthday: {
			rules: [{
				required: true,
				errorMessage: '请填写出生年月',
			}]
		}
	}
	const patientFormRef = ref(null)
	const headerArr = [{
			icon: '../../../static/img/zxcy.png',
			label: '中西成药',
			value: 1,
			templateType: 2
		},
		{
			icon: '../../../static/img/zscf.png',
			label: '注射处方',
			value: 2,
			templateType: 4
		},
		{
			icon: '../../../static/img/zycf.png',
			label: '中药处方',
			value: 4,
			templateType: 3
		},
		{
			icon: '../../../static/img/ftcf.png',
			label: '敷贴处方',
			value: 7,
			templateType: 5
		},
		{
			icon: '../../../static/img/jyzl.png',
			label: '校验治疗',
			value: 8,
			templateType: 6
		},
		{
			icon: '../../../static/img/ylqx.png',
			label: '医疗器械',
			value: 3,
			templateType: 8
		},
	]
	const prescriptions = ref([
		// {
		// 	doctorAdvice: '',
		// 	details: [],
		// 	details_Fujiafei: [],
		// 	rxType: 1,
		// 	subtotal: 0
		// },
		// {
		// 	doctorAdvice: '',
		// 	details: [],
		// 	details_Fujiafei: [],
		// 	rxType: 2,
		// 	subtotal: 0,
		// 	index: 1
		// },
		// {
		// 	doctorAdvice: '',
		// 	details: [],
		// 	details_Fujiafei: [],
		// 	rxType: 4,
		// 	subtotal: 0,
		// 	index: 1
		// },
		// {
		// 	doctorAdvice: '',
		// 	details: [],
		// 	details_Fujiafei: [],
		// 	rxType: 7,
		// 	subtotal: 0,
		// 	index: 1
		// },
		// {
		// 	doctorAdvice: '',
		// 	details: [],
		// 	details_Fujiafei: [],
		// 	rxType: 8,
		// 	subtotal: 0
		// },
		// {
		// 	doctorAdvice: '',
		// 	details: [],
		// 	details_Fujiafei: [],
		// 	rxType: 3,
		// 	subtotal: 0
		// }
	])
	const injectingDrugIndex = computed(() => {
		return prescriptions.value.findLast((a) => a.rxType === 2).index
	})
	const herbalDrugIndex = computed(() => {
		return prescriptions.value.findLast((a) => a.rxType === 4).index
	})
	const smearDrugIndex = computed(() => {
		return prescriptions.value.findLast((a) => a.rxType === 7).index
	})
	const dosformList = ref([])
	const unitFrquList = ref([])
	const usedFrquList = ref([])
	const usageList = ref([])
	const modulationmethodList = ref([])
	const ftusageaskList = ref([])
	const zyusageaskList = ref([])
	const alertTitle = ref('')
	const alertContent = ref('')
	const alertDialogRef = ref(null)
	const totalAmount = computed(() => {
		let amount = 0
		prescriptions.value.filter((a) => {
			amount += a.subtotal ?? 0
		})
		return amount
	})
	const specialtreatmentList = ref([])
	const configData = ref({})
	// 患者姓名的内容改变事件
	const nameChange = (e) => {
		console.log(e);
		patient.value.name = e

		topShowFlag.value = true;
		let query = uni.createSelectorQuery();
		let dom = query.select(".mobileInput")
		dom.fields({
			rect: true,
			scrollOffset: true
		}, function(res) {}).exec(function(eres) {})
	}
	// const handlerTag = () => {
	// 	tagFlag.value = true
	// }
	const getPatient = (val) => { // 患者信息
		patientObj = val;
	}
	onLoad((option) => {
		if (!option.id && !option.patientId) {
			return
		}
		initialization({
			id: option.id,
			patientId: option.patientId
		}).then(res => {
			patient.value = res.data.patient
			prescriptions.value = res.data.prescriptions
			caseHistory.value = res.data.caseHistory
			settlementData.value = res.data.settlement
			reservationId.value = res.data.reservationId
			disabled.value = true
			dises.value = res.data.dises
			caseHistory.value.medTypeName = medTypeArray.value[Number(e.detail.value)].key
			caseHistory.value.diagnosis = caseHistory.value.diagnosis.join(',')
			// catyData.value = {
			// 	caty:res.data.prescriptions[0].caty,
			// 	departCode:res.data.prescriptions[0].departCode,
			// 	reservationId:res.data.prescriptions[0].reservationId,
			// }
			catyData.value = res.data
		})
	})
	const init = () => {
		medTypeSelector().then(res => {
			if (res.code == 200) {
				medTypeArray.value = res.data
			}
		})
		allergicTypeSelector().then(res => {
			if (res.code == 200) {
				allergicArray.value = res.data
			}
		})
		tagSelector().then(res => {
			if (res.code == 200) {
				tagArray.value = res.data
			}
		})
		// queryConfig().then(res => {
		// 	if (res.code == 200) {
		// 		configData.value = res.data
		// 		updateConfig()

		// 	}
		// })
		getConfig()
		// reservationPage().then(res => {
		// 	if (res.code == 200) {
		// 		configData.value = res.data
		// 		updateConfig()
		// 	}
		// })


	}
	const getConfig = ()=>{
		queryConfig().then(res => {
			if (res.code == 200) {
				configData.value = res.data
				updateConfig()

			}
		})
	}
	const closeMask = (val) => {
		topShowFlag.value = val;
		homeDetailShow.value = val;
	}
	const medTypeChange = (e) => {
		caseHistory.value.medType = medTypeArray.value[Number(e.detail.value)].value;
		caseHistory.value.medTypeName = medTypeArray.value[Number(e.detail.value)].key
		// keshiIndex.value = Number(e.detail.value)
		// init();
	}
	// 弹框人员的点击
	const peopleClick = (item) => {
		disabled.value = true;
		patient.value.name = item.name;
		patient.value.tel = item.tel;
		patient.value.birthday = item.birthday;
		patient.value.age = item.age;
		patient.value.sex = item.gender == '女' ? '2' : '1';
		patient.value.peopleList = item;
		patient.value.id = item.id;
		topShowFlag.value = false;
		initialization({
			id: 491311284658245,
			patientId: 489176595996741
		}).then(res => {
			// catyData.value = {
			// 	caty:res.data.prescriptions[0].caty,
			// 	departCode:res.data.prescriptions[0].departCode,
			// 	reservationId:res.data.prescriptions[0].reservationId,
			// }
			catyData.value = res.data
		})

	}
	watchEffect(() => {
		if (patient.value.name === '') {
			patient.value.name = "";
			patient.value.tel = "";
			patient.value.birthday = "";
			patient.value.age = "";
			patient.value.sex = '1';
			disabled.value = false;
			topShowFlag.value = false;
		} else {
			patientSelector({
				// baseIdCommonInput: "1",
				SearchKey: patient.value.name,
			}).then(res => {
				if (res.code == 200) {
					peopleData.value = res.data;
				}
			})
		}
	})
	const back = () => {
		active.value = 1
	}
	const next = () => {
		patientFormRef.value.validate().then(res => {
			caseHistoryFormRef.value.validate().then(res => {

				dosformSelector().then(res => {
					if (res.code == 200) {
						dosformList.value = res.data
					}
				})
				unitFrquSelector().then(res => {
					if (res.code == 200) {
						unitFrquList.value = res.data
					}
				})
				usedFrquSelector().then(res => {
					if (res.code == 200) {
						usedFrquList.value = res.data
					}
				})
				usageSelector().then(res => {
					if (res.code == 200) {
						usageList.value = res.data
					}
				})
				modulationmethodSelector().then(res => {
					if (res.code == 200) {
						modulationmethodList.value = res.data
					}
				})
				ftusageaskSelector().then(res => {
					if (res.code == 200) {
						ftusageaskList.value = res.data
					}
				})
				zyusageaskSelector().then(res => {
					if (res.code == 200) {
						zyusageaskList.value = res.data
					}
				})
				specialtreatmentSelector().then(res => {
					if (res.code == 200) {
						specialtreatmentList.value = res.data
					}
				})
				headerArr.map((a) => {
					if (prescriptions.value.find((b) => b.rxType === a.value) === undefined) {
						prescriptions.value.push({
							doctorAdvice: '',
							details: [],
							details_Fujiafei: [],
							rxType: a.value,
							subtotal: 0,
							index: 1
						})
					}
				})
				active.value = 2
			})
		})


	}
	const showConfig = () => {
		configPopupRef.value.open('bottom')

	}
	const getTemplate = (pattern) => {
		templateType.value = pattern
		const obj = {
			"current": 1,
			"size": 99,
			"pattern": pattern,
		}
		queryTemplate(obj).then(res => {
			if (res.code == 200) {
				templateList.value = res.data.records
				templateRef.value.open('bottom')
			}
		})
	}
	const getHcList = () => {
		const obj = {
			"current": 1,
			"size": 99,
			patient: patient.id
		}
		queryHCPage(obj).then(res => {
			if (res.code == 200) {
				hcList.value = res.data.records
				hcRef.value.open('bottom')
			}
		})
	}
	const addTemplateFun = () => {
		addTemplateRef.value.open('bottom')
		// const obj = {
		// 	// template:,
		// 	// caseHistory:
		// }
		// addTemplate(obj).then(res => {
		// 	if (res.code == 200) {
		// 		console.log(res.data, '--------')
		// 		templateList.value = res.data
		// 	}
		// })
	}
	const onDefault =async () => {
		await getConfig()
		// restoreDefault().then(res => {
		// 	if (res.code == 200) {
		// 		patient.value = {
		// 			...patient.value,
		// 			...res.data
		// 		}
		// 		updateConfig()
		// 	}
		// })
	}
	const onSaveTemplate = () => {
		const obj = {
			template: {
				name: templateData.value.name
			}

		}
		addTemplate(obj).then(res => {
			if (res.code == 200) {
				patient.value = {
					...patient.value,
					...res.data
				}
				addTemplateRef.value.close()
			}
		})
	}
	const updateConfig = () => {
		const list = configArr.value.map((a) => a.children).flat(Infinity)
		showConfigList.value = list.filter((a) => configData.value[a.prop] && a.type !== 'physexm')
		showPhysexmConfig.value = list.map((a) => {
			if (configData.value[a.prop]) {
				if (a.prop === 'isUDVA') {
					return [{
							label: '裸眼远视力',
							type: 'UDVA',
							children: [{
									label: '左',
									formProp: 'leftUDVA'
								},
								{
									label: '右',
									formProp: 'rightUDVA'
								},
							]
						},
						{
							label: '裸眼近视力',
							type: 'UDVA',
							children: [{
									label: '左',
									formProp: 'leftUCNVA'
								},
								{
									label: '右',
									formProp: 'rightUCNVA'
								},
							]
						}
					]
				}
				if (a.prop === 'isWGNV') {
					return [{
							label: '戴镜远视力',
							type: 'UDVA',
							children: [{
									label: '左',
									formProp: 'leftWGFDV'
								},
								{
									label: '右',
									formProp: 'rightWGFDV'
								},
							]
						},
						{
							label: '戴镜近视力',
							type: 'UDVA',
							children: [{
									label: '左',
									formProp: 'leftWGNV'
								},
								{
									label: '右',
									formProp: 'rightWGNV'
								},
							]
						}
					]
				}
			}
			if (configData.value[a.prop] && a.type === 'physexm' && !['isUDVA', 'isWGNV'].includes(a.prop)) {
				return a
			}
		}).flat(Infinity).filter(Boolean)
		configPopupRef?.value?.close()
	}
	const onSave = () => {
		updateConfig()
	}

	const onSaveConfig = () => {
		saveTreated(configData.value).then(res => {
			updateConfig()
		})
	}
	const onClose = async ()=>{
		addTemplateRef.value.close()
		// await getConfig()
		// configPopupRef.value.close()
	}

	const physexmToggle = () => {
		showPhysexm.value = !showPhysexm.value
	}
	const addSurcharges = (list) => {
		list.push({
			surchargeName: '',
			amt: '',
			check: false
		})
	}
	const querySurchargesSelector = () => {
		surchargesSelector({
			SearchKey: '1'
		}).then(res => {
			if (res.code == 200) {
				surcharges.value = res.data
				// surchargesList.value = res.data.map((a)=> a.name)
			}
		})
		// surchargesSelectorRef.value.open('bottom')
	}
	const deleteSurcharges = (list, index) => {
		list.splice(index, 1)
	}
	const changSurcharges = (val, list, index) => {
		list[index] = {
			surchargeName: val.name,
			amt: val.amt,
			check: true
		}
	}
	const changeSurcharges = (val) => {
		console.log(val)
	}
	const selectionChange = (e) => {
		this.selectedIndexs = e.detail.index
	}
	const changeConfig = (val) => {
		for (const key in configData.value) {
			const keyList = ['id', 'createTime', 'createUser', 'createUserId', 'orgId', 'updateTime', 'updateUser',
				'updateUserId'
			]
			if (!keyList.includes(key)) {
				if (val.detail.value.includes(key)) {
					configData.value[key] = true
				} else {
					configData.value[key] = false
				}
			}
		}
	}
	const changeGrid = (e) => {
		let {
			index
		} = e.detail
		drugList.value = []
		activeHeader.value = index
		headerArr.map((a) => {
			if (a.value === index) {
				templateType.value = a.templateType
			}
		})

		// this.list[index].badge && this.list[index].badge++

		// uni.showToast({
		// 	title: `点击第${index+1}个宫格`,
		// 	icon: 'none'
		// })
	}
	const inputDrug = (val) => {
		// drugList.value = [{"stockQty":-3.0000,"stockQtyDescribe":"-3盒","categoryName":"西药中成药","display":"<span>乙</span><span>逍遥丸</span>　0.2g*200粒　九芝堂股份有限公司　库存：-3盒　零售价：18","orgId":252885263003720,"name":"逍遥丸","generalName":"九芝堂","pinYin":"xyw","barcode":"6924332730173","itemNo":"e524e0f293b241e5b516bb75d3b00629","approvalNumber":"国药准字Z43020469","validity":36,"manufacturer":"九芝堂股份有限公司","specification":"0.2g*200粒","category":1,"itemLevel":"丙","purchasingPrice":10.0000,"retailPrice":18.0000,"unit":"盒","dosageForm":null,"medListCodg":null,"medListName":null,"clearingForm":1,"inventoryMin":0.0000,"validityWarning":0,"usedFrqu":null,"dosform":null,"dosDscr":0.0000,"dosDscrUnit":null,"isBasicMedicine":false,"isContainsEphedrine":false,"isRx":false,"isImport":false,"level":1,"openingInventory":{"supplierId":488883983491141,"supplierName":"广州应用科技学院","inventory":55.0,"batchNumber":"","expiryDate":"2023-12-27 16:00:00","costPrice":10.0},"dosage":"口服，一次8丸，一日3次。","purpose":null,"taboo":null,"storage":null,"consideration":null,"enableSplit":false,"splitRatio":null,"splitUnit":null,"splitPrice":null,"lockUnit":false,"state":0,"isDelete":false,"createTime":"2023-12-02 21:04:49","updateTime":null,"createUserId":212725263002001,"updateUserId":null,"createUser":"superAdmin","updateUser":null,"id":488886629195845,"extJson":null},{"stockQty":0.0000,"stockQtyDescribe":"0罐","categoryName":"西药中成药","display":"<span>乙</span><span>板蓝根颗粒</span>　10g*20袋　广州白云山和记黄埔中药有限公司　库存：0罐　零售价：2","orgId":252885263003720,"name":"板蓝根颗粒","generalName":"白云山","pinYin":"blgkl","barcode":"6938200750774","itemNo":"f542f2aec9cd4d67b39e923821bde4de","approvalNumber":"国药准字Z44023485","validity":36,"manufacturer":"广州白云山和记黄埔中药有限公司","specification":"10g*20袋","category":1,"itemLevel":"丙","purchasingPrice":0.0000,"retailPrice":2.0000,"unit":"罐","dosageForm":null,"medListCodg":null,"medListName":null,"clearingForm":1,"inventoryMin":0.0000,"validityWarning":0,"usedFrqu":null,"dosform":null,"dosDscr":0.0000,"dosDscrUnit":null,"isBasicMedicine":false,"isContainsEphedrine":false,"isRx":false,"isImport":false,"level":1,"openingInventory":null,"dosage":"开水冲服。一次5～10克，一日3～4次。","purpose":null,"taboo":null,"storage":null,"consideration":null,"enableSplit":false,"splitRatio":null,"splitUnit":null,"splitPrice":null,"lockUnit":false,"state":0,"isDelete":false,"createTime":"2023-12-02 21:26:39","updateTime":"2023-12-03 17:33:09","createUserId":212725263002001,"updateUserId":212725263002001,"createUser":"superAdmin","updateUser":"superAdmin","id":488891992956997,"extJson":null},{"stockQty":10.0000,"stockQtyDescribe":"10盒","categoryName":"西药中成药","display":"<span>Rx</span><span>乙</span><span>测试药品</span>　测试药品　测试药品　库存：10盒　零售价：1","orgId":252885263003720,"name":"测试药品","generalName":null,"pinYin":"csyp","barcode":"123456","itemNo":"123456","approvalNumber":"123456","validity":36,"manufacturer":"测试药品","specification":"测试药品","category":1,"itemLevel":"丙","purchasingPrice":123.0000,"retailPrice":1.0000,"unit":"盒","dosageForm":"110000","medListCodg":null,"medListName":null,"clearingForm":3,"inventoryMin":123.0000,"validityWarning":6,"usedFrqu":null,"dosform":null,"dosDscr":0.0000,"dosDscrUnit":null,"isBasicMedicine":true,"isContainsEphedrine":true,"isRx":true,"isImport":true,"level":1,"openingInventory":{"supplierId":488883983491141,"supplierName":"0","inventory":123.0,"batchNumber":"123456","expiryDate":"2023-12-21 00:00:00","costPrice":123.0},"dosage":null,"purpose":null,"taboo":null,"storage":null,"consideration":null,"enableSplit":false,"splitRatio":null,"splitUnit":null,"splitPrice":null,"lockUnit":false,"state":0,"isDelete":false,"createTime":"2023-12-02 22:18:12","updateTime":"2023-12-03 15:00:45","createUserId":212725263002001,"updateUserId":212725263002001,"createUser":"superAdmin","updateUser":"superAdmin","id":488904662663237,"extJson":null},{"stockQty":0.0000,"stockQtyDescribe":"0盒","categoryName":"西药中成药","display":"<span>乙</span><span>天麻首乌胶囊</span>　0.5克*36粒　湖南国华制药有限公司　库存：0盒　零售价：28","orgId":252885263003720,"name":"天麻首乌胶囊","generalName":"国华","pinYin":"tmswjn","barcode":"6931399488886","itemNo":"05fa59d5efc6496ebd200375c1bc0733","approvalNumber":"国药准字Z20050819","validity":36,"manufacturer":"湖南国华制药有限公司","specification":"0.5克*36粒","category":1,"itemLevel":"丙","purchasingPrice":0.0000,"retailPrice":28.0000,"unit":"盒","dosageForm":null,"medListCodg":null,"medListName":null,"clearingForm":1,"inventoryMin":0.0000,"validityWarning":0,"usedFrqu":null,"dosform":null,"dosDscr":0.0000,"dosDscrUnit":null,"isBasicMedicine":false,"isContainsEphedrine":false,"isRx":false,"isImport":false,"level":1,"openingInventory":null,"dosage":"口服，一次3粒","purpose":null,"taboo":null,"storage":null,"consideration":null,"enableSplit":false,"splitRatio":null,"splitUnit":null,"splitPrice":null,"lockUnit":false,"state":0,"isDelete":false,"createTime":"2023-12-03 17:37:41","updateTime":"2023-12-03 17:38:05","createUserId":212725263002001,"updateUserId":212725263002001,"createUser":"superAdmin","updateUser":"superAdmin","id":489189615550533,"extJson":null},{"stockQty":234.0000,"stockQtyDescribe":"2341","categoryName":"西药中成药","display":"<span>Rx</span><span>乙</span><span>123</span>　213　11231　库存：2341　零售价：1","orgId":252885263003720,"name":"123","generalName":null,"pinYin":"123","barcode":"111","itemNo":"111","approvalNumber":"111","validity":36,"manufacturer":"11231","specification":"213","category":1,"itemLevel":"丙","purchasingPrice":1111.0000,"retailPrice":1.0000,"unit":"1","dosageForm":"100000","medListCodg":null,"medListName":null,"clearingForm":3,"inventoryMin":111.0000,"validityWarning":1,"usedFrqu":null,"dosform":null,"dosDscr":0.0000,"dosDscrUnit":null,"isBasicMedicine":false,"isContainsEphedrine":true,"isRx":false,"isImport":false,"level":1,"openingInventory":{"supplierId":488883983491141,"supplierName":"0","inventory":111.0,"batchNumber":"111","expiryDate":"2023-12-28 00:00:00","costPrice":1111.0},"dosage":null,"purpose":null,"taboo":null,"storage":null,"consideration":null,"enableSplit":false,"splitRatio":null,"splitUnit":null,"splitPrice":null,"lockUnit":false,"state":0,"isDelete":false,"createTime":"2023-12-09 17:20:55","updateTime":"2023-12-09 19:33:30","createUserId":212725263002001,"updateUserId":212725263002001,"createUser":"superAdmin","updateUser":"superAdmin","id":491308862476357,"extJson":null},{"stockQty":11.0000,"stockQtyDescribe":"112","categoryName":"西药中成药","display":"<span>Rx</span><span>乙</span><span>222</span>　222　222　库存：112　零售价：2","orgId":252885263003720,"name":"222","generalName":null,"pinYin":"222","barcode":"123","itemNo":"1","approvalNumber":"12","validity":36,"manufacturer":"222","specification":"222","category":1,"itemLevel":"丙","purchasingPrice":111.0000,"retailPrice":2.0000,"unit":"2","dosageForm":"100000","medListCodg":null,"medListName":null,"clearingForm":3,"inventoryMin":111.0000,"validityWarning":1,"usedFrqu":null,"dosform":null,"dosDscr":0.0000,"dosDscrUnit":null,"isBasicMedicine":false,"isContainsEphedrine":false,"isRx":false,"isImport":false,"level":1,"openingInventory":{"supplierId":488883983491141,"supplierName":"0","inventory":11.0,"batchNumber":"11","expiryDate":"2023-12-14 00:00:00","costPrice":111.0},"dosage":null,"purpose":null,"taboo":null,"storage":null,"consideration":null,"enableSplit":false,"splitRatio":null,"splitUnit":null,"splitPrice":null,"lockUnit":false,"state":0,"isDelete":false,"createTime":"2023-12-09 17:22:33","updateTime":null,"createUserId":212725263002001,"updateUserId":null,"createUser":"superAdmin","updateUser":null,"id":491309265059909,"extJson":null}]
		drugSelectore({
			SearchKey: val,
			Category: [activeHeader.value]
		}).then(res => {
			if (res.code == 200) {
				drugList.value = res.data
				console.log(drugList.value)
			}
		})
	}
	const inputTherapy = (val) => {
		therapySelector({
			SearchKey: val
		}).then(res => {
			if (res.code == 200) {
				therapyList.value = res.data.map((a) => a.display)
			}
		})
	}
	const inputDiagnosis = (val) => {
		diseaseNameSelector({
			SearchKey: val
		}).then(res => {
			if (res.code == 200) {
				diseaseNameList.value = [
					...[{
						name: val
					}],
					...res.data
				]
			}
		})
	}
	const handlerDiagnosis = (val) => {
		if (!caseHistory.value.diagnosis) {
			caseHistory.value.diagnosis = []
		}

		if (!caseHistory.value.diagnosis.find((a) => a === val.name)) {
			dises.value.push({
				...val,
				wmDiagName: val.name,
				wmDiagCode: val.diseCodg
			})
			caseHistory.value.diagnosis.push(val.name)
		}
	}
	const deleteDiagnosis = (val) => {
		const index = caseHistory.value.diagnosis.findIndex(val)
		caseHistory.value.diagnosis.splice(index, 1)
		dises.value.splice(index, 1)
	}
	const deleteAlg = (val) => {
		const index = caseHistory.value.algsHis.findIndex(val)
		caseHistory.value.algsHis.splice(index, 1)
	}
	const deleteChfcomp = (val) => {
		const index = caseHistory.value.chfcomp.findIndex(val)
		caseHistory.value.chfcomp.splice(index, 1)
	}
	const deleteTag = (val) => {
		const index = caseHistory.value.tagIds.findIndex(val)
		caseHistory.value.tagIds.splice(index, 1)
	}

	const handlerShowDiagnosis = () => {
		diagnosisRef.value.open('bottom')
	}
	const changePicker = (e, arr, index, name, list) => {
		arr[index][name] = list[Number(e.detail.value)].key
	}
	const changeDrug = (val, list, modelValue) => {
		const index = list.findIndex((a) => a.id === val.id)
		if (index === -1) {
			list.push(val)
		} else {

		}
		clearDrug.value++
	}
	const deleteDrugDetails = (list, index, name) => {
		alertTitle.value = headerArr.find((a) => a.value === activeHeader.value).label
		alertContent.value = `是否删除${name}`
		alertDialogRef.value.open()
		deleteList.value = list
		deleteIndex.value = index
	}
	const dialogConfirm = () => {
		deleteList.value.splice(deleteIndex.value, 1)
	}
	watch(() => prescriptions.value,
		(a) => {

			// const arr = prescriptions.value.filter((a) => a.rxType === 4)
			prescriptions.value.filter((a) => {
				a.subtotal = a.subtotal ?? 0
				let sum = 0;
				(a.details ?? []).map((b) => {
						sum += Number(b.retailPrice ?? 1) * Number(b.cnt ?? 1)
					});
					(a.details_Fujiafei ?? []).map((c) => {
						sum += Number(c.amt ?? 1)
					})

				a.subtotal = sum
			})
		}, {
			immediate: true,
			deep: true
		})
	const placeOrder = () => {
		const prescriptionsList = prescriptions.value.map((a) => {
			if ((a.details ?? []).length > 0) {
				return {
					...a,
					...catyData.value
				}
			}
		}).filter(Boolean)
		const obj = {
			patient: patient.value,
			prescriptions: prescriptionsList,
			caseHistory: caseHistory.value,
			dises: dises.value,
			settlement: {},
			reservationId: catyData.value.reservationId
		}
		const obj1 = {
			...catyData.value,
			dises: dises.value,
		}
		return placeAnOrder(obj1)
		// .then(res => {
		// 	if (res.code == 200) {
		// 		return res.data
		// 	}
		// })
	}
	const onPricing = async () => {
		const res = await placeOrder()
		pricing(res.data).then(res => {
			if (res.code == 200) {

			}else{
				uni.showToast({
	title: res.msg,
	duration: 2000,
	icon:'none'
});
			}
		})
	}
	const onSettle = async () => {
		const res = await placeOrder()
		settlement(res.data).then(res => {
			if (res.code == 200) {

			}else{
				uni.showToast({
	title: res.msg,
	duration: 2000,
	icon:'none'
});
			}
		})
	}
	const getDetailsTemplate = async (item) => {
		await detailsTemplate({
			id: item.templateId,
			isSplit: true
		}).then(res => {
			if (res.code == 200) {
				templateDetails.value = {
					...res.data,
					...res.data.caseHistory,
					...res.data.template
				}
			}
		})
	}
	const getDetailsHc = async (item) => {
		await hCDetails({
			id: item.reservationId,
			isSplit: true
		}).then(res => {
			if (res.code == 200) {
				hcDetailsVal.value = res.data
			}
		})
	}
	const setDetailsHc = async (item) => {
		if (!hcDetailsVal.value.caseHistory.id) {
			await getDetailsHc(item)
		}
		// patient.value  = hcDetailsVal.value.patient
		caseHistory.value = hcDetailsVal.value.caseHistory
		prescriptions.value = hcDetailsVal.value.prescriptions
		dises.value = hcDetailsVal.value.dises
		caseHistory.value.medTypeName = medTypeArray.value.find((a) => a.value === caseHistory.value.medType).key
		caseHistory.value.diagnosis = hcDetailsVal.value.dises.map((a) => a.wmDiagName)
		hcHeaderArr.value = headerArr.filter((a) => hcDetailsVal.value.prescriptions.find((b) => a.value === b
			.rxType))
		hcRef.value.close()
		hcDetailsVal.value = {
			caseHistory: {}
		}
	}
	const setDetailsTemplate = async (item) => {
		await getDetailsTemplate(item)
		if (templateType.value === 7) {
			caseHistory.value = templateDetails.value.caseHistory
			caseHistory.value.medTypeName = medTypeArray.value.find((a) => a.value === caseHistory.value.medType)
				.key
		} else {
			prescriptions.value = templateDetails.value.prescriptions
		}
		templateRef.value.close()
	}
	const addDrug = (type) => {
		const index = prescriptions.value.findLastIndex((a) => a.rxType === type)
		prescriptions.value.splice(index + 1, 0, {
			doctorAdvice: '',
			details: [],
			details_Fujiafei: [],
			rxType: type,
			subtotal: 0,
			index: prescriptions.value[index].index + 1
		})
	}
	const deleteDrug = (type, index) => {
		const prescriptionsIndex = prescriptions.value.findIndex((a) => a.rxType === type && a.index === index)
		prescriptions.value.splice(prescriptionsIndex, 1)
	}

	const handlerAlg = () => {
		inputTypeList(4)
		algRef.value.open('bottom')
	}
	const handlerChchfcomp = () => {
		inputTypeList(1)
		hchfcompRef.value.open('bottom')
	}
	const handlerTag = () => {
		inputTypeList(5)
		tagRef.value.open('bottom')

	}
	const inputTypeList = (val, type) => {
		getListByType({
			SearchKey: val,
			type: type
		}).then(res => {
			if (res.code == 200) {
				if (type === 4) {
					algList.value = res.data
				}
				if (type === 1) {
					chfcompList.value = res.data
				}
				if (type === 5) {
					tagList.value = res.data
				}
			}
		})
	}
	const onClickScan = async () => {
		try {

			let res = await uni.scanCode({
				onlyFromCamera: true, // 仅允许相机扫描
				scanType: ['barCode'], // 指定扫描的码类型为二维码

			})
			prescriptions.value = res.result
			await request()
		} catch (e) {
			if (e) {
				uni.showToast({
					title: '扫描失败',
					duration: 2000,
					icon: 'error',
				});
			}
		}
	}
	const bindDateChange = (e) => {
		patient.value.birthday = e.detail.value
	}
	init();
	updateConfig()
</script>

<style lang="scss" scoped>
	.doctor_visit {
		// width: calc(100vw - 40rpx);
		width: 100vw;
		min-height: calc(100vh - 40rpx);
		// padding: 20rpx;
		background-color: #f3f3f3;

		.input_box {
			background-color: #fff;
			padding: 20rpx;

			.inputs {
				display: inline-block;
				border: 1rpx solid #e3e3e3;
				width: calc(99% - 32rpx);
				padding: 16rpx;
				border-radius: 6rpx;
				font-size: 26rpx;
			}
		}

		.li {
			width: 100%;
			height: 80rpx;
			background-color: #fff;
			line-height: 80rpx;
			border-bottom: 1px solid #ccc;

			.sexFlag {
				width: 58rpx;
				height: 58rpx;
				vertical-align: middle;
				margin-left: 30rpx;
			}

			.name {
				margin-left: 20rpx;
			}

			.age {
				margin-left: 50rpx;
			}

			.mobile {
				float: right;
				margin-right: 30rpx;
			}
		}

		.case_box {
			background-color: #fff;
			padding: 20rpx;
			margin-top: 10rpx;
			padding-bottom: 70px;

			.case_header {
				height: 46px;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.case_right {
					display: flex;

					button {
						padding: 0 20rpx;
						margin-left: 5rpx;
					}
				}
			}
		}

	}

	.physexm_toggle {
		color: #2979ff;
	}

	.config_content {
		.config_title {
			font-weight: 600;
			margin: 20rpx 0;
		}

		.config_check {
			flex-wrap: wrap;
			display: flex;

			.config_item {
				width: 50%
			}
		}

	}

	.config_foot {
		flex-wrap: wrap;
		display: flex;

		button {
			width: 50%
		}
	}

	.physexm_form {
		flex-wrap: wrap;
		display: flex;

		.physexm_item {
			width: 50%
		}
	}

	.btn {
		// height: 8%;
		position: fixed;
		bottom: 0;
		width: 100%;
		z-index: 9;

		.button {
			color: #fff;
			background-color: #0055ff;
			position: absolute;
			width: 100%;
			bottom: 0;
			left: 0;

			&:active {
				background-color: #00aaff;
			}
		}
	}

	.footBtn {
		position: fixed;
		bottom: 0;
		width: 100%;
		display: flex;
		align-items: center;
		background: #fff;
		padding-left: 20rpx;
		display: flex;
		justify-content: space-between;
		z-index: 99999;

		button {
			margin: 0;
		}
	}

	.scanIcon {
		width: 37px;
		height: 37px;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.dispose_content {
		display: flex;
		flex-wrap: wrap;

		.left_top {
			border-bottom: 1px solid;
			border-right: 1px solid;
			width: calc(50% - 1px);
		}

		.right_top {
			border-bottom: 1px solid;
			width: 50%;
		}

		.left_bottom {
			border-right: 1px solid;
			width: calc(50% - 1px);
		}
	}

	.UDVA {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		border: 1px solid #e3e3e3;
		border-radius: 5rpx;
		padding-left: 10rpx;
	}

	.BloodPressure {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
	}

	.grid-item-box {
		text-align: center;
		height: 100%;

		.text {
			font-size: 30rpx;
			margin-bottom: 10rpx;
		}
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.flex-wrap {
		flex-wrap: nowrap;
	}

	.w-30 {
		width: 30%;
	}

	.red {
		color: red;
	}

	.white-nowrap {
		white-space: nowrap;
	}

	.demo-uni-row {
		background: #fff;
	}

	.drugContent {
		background: #fff;
		margin: 5rpx 0;
		font-size: 26rpx;


		.forms_rows {
			padding: 15rpx;


		}
	}

	.mh-300 {
		min-height: 300px;
	}

	.name {
		min-width: 100px;
		font-size: 35rpx;
		font-weight: 600;
	}

	.drugFoot {
		background: #fff;
		margin: 5rpx;
	}

	.surcharges {
		padding: 10rpx;
		justify-content: space-between;

		button {
			margin: 0;
		}


	}

	.surchargesContent {
		.surchargesItem {
			padding: 15rpx;
			background: #fff;
			border-bottom: 1px solid #ccc;
		}
	}

	.diagnosisItem {
		border: 1px solid #409EFF;
		border-radius: 15rpx;
		padding: 10rpx 20rpx;
		color: #606266;
		margin-right: 10rpx;
		margin-top: 10rpx;
	}

	.diagnosisInput {
		padding: 15rpx;
		border-bottom: 1px solid #ccc;
	}

	.diagnosisContent {
		padding: 0 15rpx;
	}

	.diagnosisSelect {
		padding: 15rpx;
		flex-wrap: wrap;
	}

	.activeDiagnosisItem {
		padding: 5rpx 10rpx;
		background-color: #ccc;
		border-radius: 10rpx;
		margin-top: 10rpx;
		margin-right: 10rpx;
		color: #606266;
	}

	.w-100 {
		width: 100%;
	}

	.h-500 {
		height: 500px;
	}

	.mr-10 {
		margin-right: 10rpx;
	}

	.space-between {
		justify-content: space-between;
	}

	.drugItem {
		border: 1px solid #E6A23C;
		border-radius: 10rpx;
		padding: 0 15rpx;
		margin-bottom: 10rpx;
	}

	.template_content {
		height: 500px;
		overflow: auto;

		.templateItem {
			height: 50px;
			justify-content: space-between;
			padding: 0 15rpx;
			border-bottom: 1px solid #f3f3f3;
		}

		.hcItem {
			height: 75px !important;
			font-size: 14px;
		}
	}

	.addDrug {
		background: #fff;
		padding: 10px 0;
	}

	.template_foot {
		position: absolute;
		bottom: 0;
		width: 100%;
		display: flex;
	}
</style>